.
This commit is contained in:
+4
-4
@@ -571,19 +571,19 @@ def loadJsonAnswer(answer):
|
||||
if (not isinstance(answer["cid"], int)) or (
|
||||
not isinstance(eid, int) or (not isinstance(answer["ans"], str))
|
||||
):
|
||||
return JsonResponse(
|
||||
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(
|
||||
return False, JsonResponse(
|
||||
{"success": False, "error": "No active exam: {}".format(eid)}
|
||||
)
|
||||
|
||||
@@ -627,7 +627,7 @@ def loadJsonAnswer(answer):
|
||||
ans.full_clean()
|
||||
ans.save()
|
||||
|
||||
return True
|
||||
return True, None
|
||||
|
||||
|
||||
@login_required
|
||||
|
||||
+4
-4
@@ -245,17 +245,17 @@ def exam_take(request, pk):
|
||||
def loadJsonAnswer(answer):
|
||||
# As access is not restricted make sure the data appears valid
|
||||
if (not isinstance(answer["cid"], int)) or (not isinstance(answer["eid"], int)):
|
||||
return JsonResponse({"success": False, "error": "invalid"})
|
||||
return False, JsonResponse({"success": False, "error": "invalid"})
|
||||
|
||||
# The model should catch invalid data but this should be less intensive
|
||||
max_int = 10000000
|
||||
if answer["cid"] > max_int or answer["eid"] > max_int:
|
||||
return JsonResponse({"success": False})
|
||||
return False, JsonResponse({"success": False})
|
||||
|
||||
exam = get_object_or_404(Exam, pk=answer["eid"])
|
||||
|
||||
if not exam.active:
|
||||
return JsonResponse(
|
||||
return False, JsonResponse(
|
||||
{"success": False, "error": "No active exam: {}".format(answer["eid"])}
|
||||
)
|
||||
|
||||
@@ -296,6 +296,6 @@ def loadJsonAnswer(answer):
|
||||
ans.full_clean()
|
||||
ans.save()
|
||||
|
||||
return True
|
||||
return True, None
|
||||
|
||||
PhysicsExamViews = ExamViews(Exam, Question, "physics", "physics", loadJsonAnswer)
|
||||
+4
-4
@@ -580,19 +580,19 @@ def loadJsonAnswer(answer):
|
||||
if (not isinstance(answer["cid"], int)) or (
|
||||
not isinstance(eid, int) or (not isinstance(answer["ans"], str))
|
||||
):
|
||||
return JsonResponse(
|
||||
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(
|
||||
return False, JsonResponse(
|
||||
{"success": False, "error": "No active exam: {}".format(eid)}
|
||||
)
|
||||
|
||||
@@ -631,7 +631,7 @@ def loadJsonAnswer(answer):
|
||||
ans.full_clean()
|
||||
ans.save()
|
||||
|
||||
return True
|
||||
return True, None
|
||||
|
||||
|
||||
# @user_passes_test(user_is_admin, login_url="/accounts/login")
|
||||
|
||||
Reference in New Issue
Block a user