Enhance user marking query to ensure distinct exams and order by name for better organization

This commit is contained in:
Ross
2026-01-04 13:02:59 +00:00
parent d7682ab31d
commit 443d93c35f
+8 -4
View File
@@ -289,12 +289,16 @@ def user_marking_partial(request, exam_type: str):
return HttpResponse("Unknown exam type", status=400)
# Exams where user is an author or an authorised marker
exams_qs = ExamModel.objects.filter(
archive=False, exam_mode=True
).filter(Q(author=user) | Q(markers=user)).prefetch_related("author", "markers")
exams_qs = (
ExamModel.objects.filter(archive=False, exam_mode=True)
.filter(Q(author=user) | Q(markers=user))
.distinct()
.order_by("name")
.prefetch_related("author", "markers")
)
exams_data = []
for exam in exams_qs.order_by("name"):
for exam in exams_qs:
has_unmarked = False
unmarked_count = 0
# iterate questions and use their helper to count unmarked answers when available