Implement HTMX support for CID and User candidates lists, and add submitted candidates summary
This commit is contained in:
+38
-11
@@ -2183,23 +2183,20 @@ class ExamViews(View, LoginRequiredMixin):
|
||||
if not request.user.is_superuser:
|
||||
raise PermissionDenied
|
||||
|
||||
cid_users = (
|
||||
exam.valid_cid_users.all()
|
||||
) # .order_by("cid")#.prefetch_related("*")
|
||||
cid_user_count = len(cid_users)
|
||||
# Avoid loading large querysets here — the detailed lists are
|
||||
# rendered by HTMX partials which will fetch the data separately.
|
||||
cid_user_count = exam.valid_cid_users.count()
|
||||
user_user_count = exam.valid_user_users.count()
|
||||
|
||||
user_users = exam.valid_user_users.all() # .order_by("username")
|
||||
user_user_count = len(user_users)
|
||||
|
||||
user_exam_data = exam.cid_users.all().prefetch_related("cid_user", "user_user")
|
||||
# Provide a lightweight indicator if there are any submissions so the
|
||||
# template can decide whether to load the submitted-list partial.
|
||||
has_submissions = exam.cid_users.exists()
|
||||
|
||||
context = {
|
||||
"exam": exam,
|
||||
"cid_users": cid_users,
|
||||
"cid_user_count": cid_user_count,
|
||||
"user_exam_data": user_exam_data,
|
||||
"user_users": user_users,
|
||||
"user_user_count": user_user_count,
|
||||
"has_submissions": has_submissions,
|
||||
"app_name": self.app_name,
|
||||
}
|
||||
|
||||
@@ -2208,6 +2205,36 @@ class ExamViews(View, LoginRequiredMixin):
|
||||
|
||||
return render(request, "exam_cids.html", context)
|
||||
|
||||
def exam_cids_cid_list(self, request, exam_id):
|
||||
"""HTMX partial returning the CID candidates list for an exam."""
|
||||
exam = get_object_or_404(self.Exam, pk=exam_id)
|
||||
if request.user not in exam.author.all() and not request.user.is_superuser:
|
||||
raise PermissionDenied
|
||||
|
||||
cid_users = exam.valid_cid_users.all()
|
||||
|
||||
return render(request, "generic/partials/exam_cids_cid_list.html", {"cid_users": cid_users, "exam": exam})
|
||||
|
||||
def exam_cids_user_list(self, request, exam_id):
|
||||
"""HTMX partial returning the User candidates list for an exam."""
|
||||
exam = get_object_or_404(self.Exam, pk=exam_id)
|
||||
if request.user not in exam.author.all() and not request.user.is_superuser:
|
||||
raise PermissionDenied
|
||||
|
||||
user_users = exam.valid_user_users.all()
|
||||
|
||||
return render(request, "generic/partials/exam_cids_user_list.html", {"user_users": user_users, "exam": exam})
|
||||
|
||||
def exam_cids_submitted_list(self, request, exam_id):
|
||||
"""HTMX partial returning the submitted candidates summary."""
|
||||
exam = get_object_or_404(self.Exam, pk=exam_id)
|
||||
if request.user not in exam.author.all() and not request.user.is_superuser:
|
||||
raise PermissionDenied
|
||||
|
||||
user_exam_data = exam.cid_users.all().prefetch_related("cid_user", "user_user")
|
||||
|
||||
return render(request, "generic/partials/exam_cids_submitted_list.html", {"user_exam_data": user_exam_data, "exam": exam})
|
||||
|
||||
# def exam_groups_edit(self, request, exam_id):
|
||||
# exam = get_object_or_404(self.Exam, pk=exam_id)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user