diff --git a/longs/views.py b/longs/views.py index 82acfe76..d9232cba 100755 --- a/longs/views.py +++ b/longs/views.py @@ -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 diff --git a/physics/views.py b/physics/views.py index 967d9665..3162c615 100644 --- a/physics/views.py +++ b/physics/views.py @@ -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) \ No newline at end of file diff --git a/rapids/views.py b/rapids/views.py index 5faa5816..b5560cee 100755 --- a/rapids/views.py +++ b/rapids/views.py @@ -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")