Enhance exam status management with HTMX loading indicators and streamline AJAX handling by removing legacy jQuery code
This commit is contained in:
+18
-2
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user