diff --git a/physics/templates/physics/exam_take.html b/physics/templates/physics/exam_take.html index dc02a5c3..9915dd82 100755 --- a/physics/templates/physics/exam_take.html +++ b/physics/templates/physics/exam_take.html @@ -18,7 +18,7 @@ [{{ pos|add:1 }}/{{ exam_length }}]
- {% include 'physics/partials/exam_flag_button.html' %} +
@@ -69,6 +69,27 @@ }catch(e){ console && console.error && console.error(e); } }; + {% include "physics/exam_take_help.html" %} diff --git a/physics/templates/physics/partials/exam_take_fragment.html b/physics/templates/physics/partials/exam_take_fragment.html index 8d8000a6..5c9155b3 100644 --- a/physics/templates/physics/partials/exam_take_fragment.html +++ b/physics/templates/physics/partials/exam_take_fragment.html @@ -1,4 +1,6 @@
+ + {% include 'physics/partials/exam_flag_button.html' %}
@@ -134,6 +136,14 @@ // build the question menu locally so it is available after fragment swaps $('#menu-list').empty(); + const serverAnswered = {{ answered_json|default:'null'|safe }}; + const serverFlagged = {{ flagged_json|default:'null'|safe }}; + if ((!window.examQuestionAnswered || !Array.isArray(window.examQuestionAnswered)) && Array.isArray(serverAnswered)) { + window.examQuestionAnswered = serverAnswered; + } + if ((!window.examQuestionFlagged || !Array.isArray(window.examQuestionFlagged)) && Array.isArray(serverFlagged)) { + window.examQuestionFlagged = serverFlagged; + } const answeredArr = (window.examQuestionAnswered && Array.isArray(window.examQuestionAnswered)) ? window.examQuestionAnswered : null; const flaggedArr = (window.examQuestionFlagged && Array.isArray(window.examQuestionFlagged)) ? window.examQuestionFlagged : null; for (let i = 0; i < {{ exam_length }}; i++) { diff --git a/physics/views.py b/physics/views.py index 4733828d..40699328 100644 --- a/physics/views.py +++ b/physics/views.py @@ -485,6 +485,16 @@ def exam_take_fragment(request, pk: int, sk: int, cid: str | None = None, passco "saved_answer": saved_answer, "answer": answer, "flagged": flagged, + "answered_json": json.dumps([ + True if (q.cid_user_answers.filter(cid=cid, exam=exam).exists() if cid is not None else q.cid_user_answers.filter(user=request.user, exam=exam).exists()) else False + for q in questions + ]), + "flagged_json": json.dumps([ + (Flag.objects.filter(content_type=ContentType.objects.get_for_model(q), object_id=q.pk).filter(cid_user__cid=cid).exists() + if cid is not None + else Flag.objects.filter(content_type=ContentType.objects.get_for_model(q), object_id=q.pk).filter(user=request.user).exists()) + for q in questions + ]), "passcode": passcode, "cid_user_exam": cid_user_exam, },