From 2ff857621a5a74a79063c4c734dc174b8571354d Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 10 Nov 2025 21:56:41 +0000 Subject: [PATCH] Refactor exam take functionality to redirect to full overview page instead of returning HTMX fragment --- physics/views.py | 40 ++++------------------------------------ 1 file changed, 4 insertions(+), 36 deletions(-) diff --git a/physics/views.py b/physics/views.py index b09ec09c..43229fd9 100644 --- a/physics/views.py +++ b/physics/views.py @@ -282,42 +282,10 @@ def exam_take(request, pk: int, sk: int, cid: str | None = None, passcode: str | return exam_take_fragment(request, pk=pk, sk=pos - 1, cid=cid, passcode=passcode) return redirect(take_url, sk=pos - 1, **kwargs) elif "finish" in request.POST: - # For HTMX clients, return an overview fragment so the page can - # update in-place instead of performing a full-page redirect. - if is_htmx: - # Build the same context used by exam_take_overview - questions = exam.get_questions() - if cid is not None: - answers = UserAnswer.objects.filter(cid=cid, exam=exam) - else: - answers = UserAnswer.objects.filter(user=request.user, exam=exam) - - answer_question_map = {ans.question: ans for ans in answers} - - question_answer_tuples = [] - answer_count = 0 - for q in questions: - if q in answer_question_map: - question_answer_tuples.append((q, answer_question_map[q])) - answer_count += 1 - else: - question_answer_tuples.append((q, None)) - - cid_user_exam = exam.get_or_create_cid_user_exam(cid=cid, user_user=request.user) - - return render( - request, - "physics/partials/exam_take_overview_fragment.html", - { - "exam": exam, - "cid": cid, - "question_answer_tuples": question_answer_tuples, - "answer_count": answer_count, - "exam_length": len(questions), - "passcode": passcode, - "cid_user_exam": cid_user_exam, - }, - ) + # The overview is a full page; always navigate to the overview + # URL rather than returning an HTMX fragment. This ensures a + # consistent full-page overview experience (and prevents the + # overview HTML from being swapped into the question container). return redirect(finish_url, **kwargs) elif "save" in request.POST: # Save action should not trigger a full-page load for HTMX clients.