allow resenting of exam answers

This commit is contained in:
Ross
2024-07-29 12:43:01 +01:00
parent 2ebb0b4473
commit cf48453e6f
6 changed files with 51 additions and 7 deletions
+25 -3
View File
@@ -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("<b>Answers reset</b>")
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)