diff --git a/atlas/templates/atlas/collection_detail.html b/atlas/templates/atlas/collection_detail.html index 8b7ee981..f81c9926 100644 --- a/atlas/templates/atlas/collection_detail.html +++ b/atlas/templates/atlas/collection_detail.html @@ -58,7 +58,7 @@ hx-post="{% url 'atlas:collection_reset_answers' collection.pk %}" >Reset all answers - + {% endif %} {% include 'exam_overview_js.html' %} {% endblock %} diff --git a/atlas/views.py b/atlas/views.py index 557e1128..1ebbf5ee 100755 --- a/atlas/views.py +++ b/atlas/views.py @@ -2835,7 +2835,7 @@ def collection_reset_answers(request, exam_id: int): collection.exam_user_status.all().delete() # CidUserExams - collection.cid_users.delete() + collection.cid_users.all().delete() else: diff --git a/generic/templates/generic/exam_overview_headers.html b/generic/templates/generic/exam_overview_headers.html index 602de13c..6252c11a 100644 --- a/generic/templates/generic/exam_overview_headers.html +++ b/generic/templates/generic/exam_overview_headers.html @@ -36,6 +36,23 @@ Exam mode: {{ exam.exam_mode }}
{% if exam.exam_mode %} Cid candidates: {{candidate_count.0}}, User candidates: {{candidate_count.1}}
{% endif %} + +
+ Answer management + +
+

Manage answers for this collection.

+ + Please note these are permanant and cannot be undone. +
+ + + +
+ Open access: {{ exam.open_access }}
{% if exam.start_date %} @@ -66,3 +83,5 @@ Open access: {{ exam.open_access }}
Author(s): {% for author in exam.author.all %} {{ author }}{% if not forloop.last %}, {% endif %} {% endfor %}
+ + diff --git a/generic/urls.py b/generic/urls.py index 00ef7ce8..2978bd18 100755 --- a/generic/urls.py +++ b/generic/urls.py @@ -343,6 +343,11 @@ def generic_exam_urls(generic_exam_view: GenericExamViews): path("exam/", generic_exam_view.exam_list, name="exam_list"), path("exam/all", generic_exam_view.exam_list_all, name="exam_list_all"), path("exam//cids", generic_exam_view.exam_cids, name="exam_cids"), + path( + "exam//reset_answers", + generic_exam_view.exam_reset_answers, + name="exam_reset_answers", + ), path( "exam//cids/edit", generic_exam_view.exam_cids_edit, diff --git a/generic/views.py b/generic/views.py index 8ca56f96..cd4e16b2 100644 --- a/generic/views.py +++ b/generic/views.py @@ -1042,6 +1042,29 @@ class ExamViews(View, LoginRequiredMixin): return render(request, "exam_users_edit.html", context) + def exam_reset_answers(self, request, exam_id): + if request.htmx: + exam = get_object_or_404(self.Exam, pk=exam_id) + + if not request.user.groups.filter(name="cid_user_manager").exists(): + # raise PermissionDenied + if request.user not in exam.author.all(): + raise PermissionDenied + + ## Delete all answers + exam.cid_user_answers.all().delete() + + # User statuses + exam.exam_user_status.all().delete() + + # CidUserExams + exam.cid_users.all().delete() + + return HttpResponse("Answers reset") + + else: + raise Http404("Invalid request") + def exam_cids_edit(self, request, exam_id): exam = get_object_or_404(self.Exam, pk=exam_id) @@ -2166,9 +2189,8 @@ class ExamViews(View, LoginRequiredMixin): # so we need to check for those if self.app_name == "longs": for question in questions: - #if question not in by_question: - # continue - + # If either question or user do not exist we give a default + # not answered == score of 3 if user not in by_question[question]: #print("NOT in") by_question[question][user] = ("Not answered", 3.0) diff --git a/longs/templates/longs/exam_scores.html b/longs/templates/longs/exam_scores.html index 32e8f331..b389e1d7 100644 --- a/longs/templates/longs/exam_scores.html +++ b/longs/templates/longs/exam_scores.html @@ -2,8 +2,6 @@ {% extends 'generic/exam_scores_base.html' %} {% block table_answers %} -aoeu -eu {% for question in questions %} Question {{forloop.counter}}