Skip to content

Commit 868d784

Browse files
committed
Send action in proper json for quiz reports
Fixes TypeError: In order to allow non-dict objects to be serialized set the safe parameter to False.
1 parent 86d0526 commit 868d784

2 files changed

Lines changed: 10 additions & 11 deletions

File tree

tin/apps/assignments/views.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -725,22 +725,20 @@ def quiz_report_view(request, assignment_id):
725725
content = request.GET.get("content", "")
726726
severity = int(request.GET.get("severity", 0))
727727

728-
if assignment.quiz.ended_for_student(request.user):
729-
json_data = json.dumps("no action")
730-
else:
728+
action = "no action"
729+
730+
if not assignment.quiz.ended_for_student(request.user):
731731
LogMessage.objects.create(
732732
quiz=assignment.quiz, student=request.user, content=content, severity=severity
733733
)
734734

735-
resp = "no action"
736735
if severity >= settings.QUIZ_ISSUE_THRESHOLD:
737736
if assignment.quiz.action == "1":
738-
resp = "color"
737+
action = "color"
739738
elif assignment.quiz.action == "2":
740-
resp = "lock"
739+
action = "lock"
741740

742-
json_data = json.dumps(resp)
743-
return http.JsonResponse(json_data)
741+
return http.JsonResponse({"action": action})
744742

745743

746744
@login_required

tin/templates/assignments/quiz.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,12 @@
7979
"severity": severity,
8080
},
8181
success: function (data) {
82-
console.log(data);
83-
if (data == "color") {
82+
const action = data.action;
83+
console.log(action);
84+
if (action === "color") {
8485
document.body.style.backgroundColor = "#F72F35";
8586
}
86-
if (data == "lock") {
87+
if (action === "lock") {
8788
document.location = "{% url 'assignments:show' assignment.id %}";
8889
}
8990
},

0 commit comments

Comments
 (0)