.
This commit is contained in:
+7
-7
@@ -238,19 +238,19 @@ def loadJsonAnswer(answer):
|
|||||||
if (not isinstance(answer["cid"], int)) or (
|
if (not isinstance(answer["cid"], int)) or (
|
||||||
not isinstance(eid, int) or (not isinstance(answer["ans"], str))
|
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
|
# The model should catch invalid data but this should be less intensive
|
||||||
max_int = 999999999999999999999
|
max_int = 999999999999999999999
|
||||||
if answer["cid"] > max_int or eid > max_int:
|
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)
|
exam = get_object_or_404(Exam, pk=eid)
|
||||||
|
|
||||||
if not exam.active:
|
#if not exam.active:
|
||||||
return JsonResponse(
|
# return False, JsonResponse(
|
||||||
{"success": False, "error": "No active exam: {}".format(eid)}
|
# {"success": False, "error": "No active exam: {}".format(eid)}
|
||||||
)
|
# )
|
||||||
|
|
||||||
exiting_answers = CidUserAnswer.objects.filter(
|
exiting_answers = CidUserAnswer.objects.filter(
|
||||||
question__id=answer["qid"], exam__id=eid, cid=answer["cid"]
|
question__id=answer["qid"], exam__id=eid, cid=answer["cid"]
|
||||||
@@ -272,7 +272,7 @@ def loadJsonAnswer(answer):
|
|||||||
ans.full_clean()
|
ans.full_clean()
|
||||||
ans.save()
|
ans.save()
|
||||||
|
|
||||||
return True
|
return True, None
|
||||||
|
|
||||||
|
|
||||||
#@csrf_exempt
|
#@csrf_exempt
|
||||||
|
|||||||
+2
-2
@@ -433,12 +433,12 @@ class ExamViews(View, LoginRequiredMixin):
|
|||||||
n = 0
|
n = 0
|
||||||
|
|
||||||
for answer in json.loads(request.POST.get("answers")):
|
for answer in json.loads(request.POST.get("answers")):
|
||||||
ret = self.loadJsonAnswer(answer)
|
ret_status, ret = self.loadJsonAnswer(answer)
|
||||||
|
|
||||||
#if ret is not True:
|
#if ret is not True:
|
||||||
# return ret
|
# return ret
|
||||||
|
|
||||||
if ret:
|
if ret_status:
|
||||||
n = n + 1
|
n = n + 1
|
||||||
else:
|
else:
|
||||||
return ret
|
return ret
|
||||||
|
|||||||
Reference in New Issue
Block a user