Enhance exam overview and fragment by adding question status indicators for answered and flagged questions
This commit is contained in:
+26
-4
@@ -186,12 +186,23 @@ def exam_take_overview(request, pk, cid=None, passcode=None):
|
||||
question_answer_tuples = []
|
||||
answer_count = 0
|
||||
for q in questions:
|
||||
# if q in answer_question_map and answer_question_map[q].answer:
|
||||
if q in answer_question_map: # might need to improve this
|
||||
question_answer_tuples.append((q, answer_question_map[q]))
|
||||
if q in answer_question_map:
|
||||
ans = answer_question_map[q]
|
||||
answer_count += 1
|
||||
else:
|
||||
question_answer_tuples.append((q, None))
|
||||
ans = None
|
||||
# compute flagged state for this question+actor
|
||||
try:
|
||||
ct = ContentType.objects.get_for_model(q)
|
||||
flags_qs = Flag.objects.filter(content_type=ct, object_id=q.pk)
|
||||
if cid is not None:
|
||||
flags_qs = flags_qs.filter(cid_user__cid=cid)
|
||||
else:
|
||||
flags_qs = flags_qs.filter(user=request.user)
|
||||
flagged = flags_qs.exists()
|
||||
except Exception:
|
||||
flagged = False
|
||||
question_answer_tuples.append((q, ans, flagged))
|
||||
|
||||
cid_user_exam = exam.get_or_create_cid_user_exam(cid=cid, user_user=request.user)
|
||||
|
||||
@@ -380,6 +391,17 @@ def exam_take(request, pk: int, sk: int, cid: str | None = None, passcode: str |
|
||||
"passcode": passcode,
|
||||
"cid_user_exam": cid_user_exam,
|
||||
"flagged": flagged,
|
||||
# minimal per-question status for client-side menu: answered/flagged lists
|
||||
"answered_json": json.dumps([
|
||||
True if (question.cid_user_answers.filter(cid=cid, exam=exam).exists() if cid is not None else question.cid_user_answers.filter(user=request.user, exam=exam).exists()) else False
|
||||
for question in questions
|
||||
]),
|
||||
"flagged_json": json.dumps([
|
||||
(Flag.objects.filter(content_type=ContentType.objects.get_for_model(question), object_id=question.pk).filter(cid_user__cid=cid).exists()
|
||||
if cid is not None
|
||||
else Flag.objects.filter(content_type=ContentType.objects.get_for_model(question), object_id=question.pk).filter(user=request.user).exists())
|
||||
for question in questions
|
||||
]),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user