Enhance exam status management with HTMX loading indicators and streamline AJAX handling by removing legacy jQuery code

This commit is contained in:
Ross
2025-12-29 12:44:42 +00:00
parent 4ecc32f837
commit 94fbd38634
5 changed files with 140 additions and 129 deletions
+18 -2
View File
@@ -1112,9 +1112,25 @@ class ExamViews(View, LoginRequiredMixin):
exam = get_object_or_404(self.Exam, pk=pk)
exam.archive = True if request.POST.get("archive") == "true" else False
print(f"{exam.archive=}")
# Support both legacy JSON POSTs and HTMX button toggles.
# If this is an HTMX request, toggle the archive flag and
# return the `exam-archived` partial for in-place replacement.
is_htmx = request.headers.get("HX-Request") == "true"
if is_htmx:
exam.archive = not exam.archive
else:
# Legacy POST expects 'archive' == 'true'
exam.archive = True if request.POST.get("archive") == "true" else False
exam.save()
if is_htmx:
return render(
request,
"generic/partials/exams/exam_status.html#exam-archived",
{"exam": exam, "collection": exam},
)
data = {
"status": "success",
"archive": exam.archive,