Enhance exam take functionality to support HX-Redirect for HTMX clients, ensuring full navigation experience
This commit is contained in:
+15
-4
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user