Enhance exam take functionality to support HX-Redirect for HTMX clients, ensuring full navigation experience

This commit is contained in:
Ross
2025-11-10 21:58:12 +00:00
parent 2ff857621a
commit 200a6e2a1c
+15 -4
View File
@@ -282,10 +282,21 @@ 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:
# 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).
# The overview is a full page. For HTMX clients, instruct the
# browser to perform a full navigation by returning an HX-Redirect
# header (htmx will set window.location). For non-HTMX clients,
# perform a normal redirect.
if is_htmx:
try:
url = reverse(finish_url, kwargs=kwargs)
except Exception:
# Fallback: build a simple redirect response
resp = HttpResponse()
resp["HX-Redirect"] = ""
return resp
resp = HttpResponse()
resp["HX-Redirect"] = url
return resp
return redirect(finish_url, **kwargs)
elif "save" in request.POST:
# Save action should not trigger a full-page load for HTMX clients.