This commit is contained in:
Ross
2021-08-02 12:00:29 +01:00
parent 694d629c74
commit 0b367312c5
2 changed files with 9 additions and 9 deletions
+7 -7
View File
@@ -238,19 +238,19 @@ def loadJsonAnswer(answer):
if (not isinstance(answer["cid"], int)) or (
not isinstance(eid, int) or (not isinstance(answer["ans"], str))
):
return JsonResponse({"success": False, "error": "cid or eid or answers not defined"})
return False, JsonResponse({"success": False, "error": "cid or eid or answers not defined"})
# The model should catch invalid data but this should be less intensive
max_int = 999999999999999999999
if answer["cid"] > max_int or eid > max_int:
return JsonResponse({"success": False, "error": "invalid cid"})
return False, JsonResponse({"success": False, "error": "invalid cid"})
exam = get_object_or_404(Exam, pk=eid)
if not exam.active:
return JsonResponse(
{"success": False, "error": "No active exam: {}".format(eid)}
)
#if not exam.active:
# return False, JsonResponse(
# {"success": False, "error": "No active exam: {}".format(eid)}
# )
exiting_answers = CidUserAnswer.objects.filter(
question__id=answer["qid"], exam__id=eid, cid=answer["cid"]
@@ -272,7 +272,7 @@ def loadJsonAnswer(answer):
ans.full_clean()
ans.save()
return True
return True, None
#@csrf_exempt
+2 -2
View File
@@ -433,12 +433,12 @@ class ExamViews(View, LoginRequiredMixin):
n = 0
for answer in json.loads(request.POST.get("answers")):
ret = self.loadJsonAnswer(answer)
ret_status, ret = self.loadJsonAnswer(answer)
#if ret is not True:
# return ret
if ret:
if ret_status:
n = n + 1
else:
return ret