Skip to content

Commit 46825a6

Browse files
jsb2092claude
andcommitted
Format True/False answers properly in quiz results
- Convert boolean selected value to 'True'/'False' string for display - Extract text from response_data object for short/long answers - Extract selected value for multiple choice Fixes [object Object] showing instead of actual answer. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent b186bb8 commit 46825a6

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

questionbank/quizzes/views.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,11 +648,21 @@ def get(self, request, code):
648648
if quiz.show_correct_answers:
649649
responses = []
650650
for resp in submission.responses.select_related('question').order_by('question_number'):
651+
# Format student's answer for display
652+
response_data = resp.response_data or {}
653+
if resp.question.question_type == 'multipleChoice':
654+
your_answer = response_data.get('selected', '')
655+
elif resp.question.question_type == 'trueFalse':
656+
selected = response_data.get('selected')
657+
your_answer = 'True' if selected else 'False' if selected is not None else ''
658+
else:
659+
your_answer = response_data.get('text', '')
660+
651661
resp_data = {
652662
'question_number': resp.question_number,
653663
'question_text': resp.question.text,
654664
'question_type': resp.question.question_type,
655-
'your_answer': resp.response_data,
665+
'your_answer': your_answer,
656666
'points_earned': float(resp.get_final_score()) if resp.get_final_score() else 0,
657667
'points_possible': float(resp.points_possible),
658668
'is_correct': resp.is_correct,
@@ -664,7 +674,8 @@ def get(self, request, code):
664674
if resp.question.question_type == 'multipleChoice':
665675
resp_data['correct_answer'] = answer_data.get('correct')
666676
elif resp.question.question_type == 'trueFalse':
667-
resp_data['correct_answer'] = answer_data.get('correct')
677+
correct = answer_data.get('correct')
678+
resp_data['correct_answer'] = 'True' if correct else 'False' if correct is not None else ''
668679
else:
669680
resp_data['correct_answer'] = answer_data.get('solution')
670681

0 commit comments

Comments
 (0)