Implement timed-out submission handling and AJAX response for collection case view
This commit is contained in:
@@ -2786,11 +2786,33 @@ def collection_case_view_take(
|
||||
raise Http404("Self review not enabled")
|
||||
answer.completed = True
|
||||
|
||||
# If this was a timed-out submission, mark as completed
|
||||
if request.POST.get('timed_out') == '1':
|
||||
answer.completed = True
|
||||
|
||||
answer.save()
|
||||
|
||||
cid_user_exam.end_time = timezone.now()
|
||||
cid_user_exam.save()
|
||||
|
||||
# If this was an AJAX/HTMX request, return JSON so the client
|
||||
# can remain on the same page and update the UI without redirect.
|
||||
# Detect HTMX/XHR requests robustly. HTMX sets the HX-Request header.
|
||||
is_ajax = (
|
||||
request.headers.get('HX-Request', '').lower() == 'true'
|
||||
or request.headers.get('x-requested-with') == 'XMLHttpRequest'
|
||||
or getattr(request, 'htmx', False)
|
||||
)
|
||||
if is_ajax:
|
||||
from django.http import JsonResponse
|
||||
return JsonResponse(
|
||||
{
|
||||
'status': 'ok',
|
||||
'locked': answer.completed,
|
||||
'submitted_at': answer.submitted_at.isoformat() if getattr(answer, 'submitted_at', None) else None,
|
||||
}
|
||||
)
|
||||
|
||||
if cid is not None:
|
||||
kwargs = {"pk": pk, "cid": cid, "passcode": passcode}
|
||||
redirect_url = "atlas:collection_case_view_take"
|
||||
|
||||
Reference in New Issue
Block a user