From a3712959ec18609cea879f3d025ca24289e5bd5d Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 13 Oct 2025 13:22:26 +0100 Subject: [PATCH] Enhance form rendering with crispy forms and improve answer timestamp handling in collection views --- .../atlas/collection_case_view_take.html | 41 ++++++++++++++----- atlas/templates/atlas/collection_history.html | 6 +-- atlas/views.py | 6 +-- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/atlas/templates/atlas/collection_case_view_take.html b/atlas/templates/atlas/collection_case_view_take.html index 856353eb..a1bda017 100644 --- a/atlas/templates/atlas/collection_case_view_take.html +++ b/atlas/templates/atlas/collection_case_view_take.html @@ -1,4 +1,5 @@ {% extends 'atlas/base.html' %} +{% load crispy_forms_tags %} {% block content %} Collection: {{collection}} @@ -218,7 +219,7 @@ {{form.json.errors}}
- {{form}} + {{form | crispy}}
@@ -345,6 +346,24 @@ // Question time limit countdown + auto-submit $(function () { + + function lockQuestion() { + // Only disable save buttons to prevent further saves + $form = $('form.post-form'); + var $saveBtns = $form.find('button[name="save"], #id_answer'); + if ($saveBtns.length) { + $saveBtns.prop('disabled', true); + } + + // Visual feedback: set timer to Locked and progress to red + $progressInner = $('#question-timer-progress-inner'); + $('#question-timer').text('Locked'); + $progressInner.css('background', '#dc3545'); + $progressInner.css('width', '0%'); + + $("#question-timer-progress-outer").hide(); + } + try { var timeLimit = {{ collection.question_time_limit|default:'null' }}; var questionCompleted = {{ question_completed|yesno:"true,false" }}; @@ -354,6 +373,15 @@ if (!timeLimit || questionCompleted) { return; } + + {% if answer %} + if ({{answer.completed|yesno:"true,false"}}) { + lockQuestion(); + console.debug('Timer: answer already completed, aborting timer init'); + return; + } + {% endif %} + var $timer = $('#question-timer'); var $form = $('form.post-form'); @@ -434,16 +462,7 @@ console.debug('No JSON response from timed_out request', e); } - // Only disable save buttons to prevent further saves - var $saveBtns = $form.find('button[name="save"], #id_answer'); - if ($saveBtns.length) { - $saveBtns.prop('disabled', true); - } - - // Visual feedback: set timer to Locked and progress to red - $('#question-timer').text('Locked'); - $progressInner.css('background', '#dc3545'); - $progressInner.css('width', '0%'); + lockQuestion(); var msg = 'Answer auto-submitted'; if (resp && resp.submitted_at) { diff --git a/atlas/templates/atlas/collection_history.html b/atlas/templates/atlas/collection_history.html index 98db9347..dad61929 100644 --- a/atlas/templates/atlas/collection_history.html +++ b/atlas/templates/atlas/collection_history.html @@ -34,13 +34,13 @@