Refactor exam question fragment to move flag button inside the fragment for HTMX updates and enhance local state management for answered and flagged questions.

This commit is contained in:
Ross
2026-01-05 14:30:55 +00:00
parent 8c796c3048
commit db51ef23be
3 changed files with 42 additions and 1 deletions
+10
View File
@@ -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,
},