.
This commit is contained in:
+56
-56
@@ -311,65 +311,65 @@ def exam_take(request, pk, sk, cid, passcode):
|
||||
)
|
||||
|
||||
|
||||
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 False, JsonResponse({"success": False, "error": "invalid"})
|
||||
|
||||
# The model should catch invalid data but this should be less intensive
|
||||
max_int = 2147483647
|
||||
if answer["cid"] > max_int or answer["eid"] > max_int:
|
||||
return False, JsonResponse({"success": False, "error": "invalid candidate id"})
|
||||
|
||||
exam = get_object_or_404(Exam, pk=answer["eid"])
|
||||
|
||||
# if not exam.active:
|
||||
# return False, JsonResponse(
|
||||
# {"success": False, "error": "No active exam: {}".format(answer["eid"])}
|
||||
# )
|
||||
|
||||
questions = defaultdict(dict)
|
||||
|
||||
for q, n, a in answer["ans"]:
|
||||
questions[q][n] = a
|
||||
pass
|
||||
|
||||
for qid in questions:
|
||||
exiting_answers = CidUserAnswer.objects.filter(
|
||||
question__id=qid, exam__id=answer["eid"], cid=answer["cid"]
|
||||
)
|
||||
|
||||
a = questions[qid]["a"]
|
||||
b = questions[qid]["b"]
|
||||
c = questions[qid]["c"]
|
||||
d = questions[qid]["d"]
|
||||
e = questions[qid]["e"]
|
||||
|
||||
if not exiting_answers:
|
||||
ans = CidUserAnswer(a=a, b=b, c=c, d=d, e=e, cid=answer["cid"])
|
||||
ans.question_id = qid
|
||||
ans.exam_id = answer["eid"]
|
||||
|
||||
ans.full_clean()
|
||||
|
||||
ans.save()
|
||||
else:
|
||||
# Update an existing answer
|
||||
# should never be more than one (famous last words)
|
||||
ans = exiting_answers[0]
|
||||
ans.a = a
|
||||
ans.b = b
|
||||
ans.c = c
|
||||
ans.d = d
|
||||
ans.e = e
|
||||
ans.full_clean()
|
||||
ans.save()
|
||||
|
||||
return True, None
|
||||
#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 False, JsonResponse({"success": False, "error": "invalid"})
|
||||
#
|
||||
# # The model should catch invalid data but this should be less intensive
|
||||
# max_int = 2147483647
|
||||
# if answer["cid"] > max_int or answer["eid"] > max_int:
|
||||
# return False, JsonResponse({"success": False, "error": "invalid candidate id"})
|
||||
#
|
||||
# exam = get_object_or_404(Exam, pk=answer["eid"])
|
||||
#
|
||||
# # if not exam.active:
|
||||
# # return False, JsonResponse(
|
||||
# # {"success": False, "error": "No active exam: {}".format(answer["eid"])}
|
||||
# # )
|
||||
#
|
||||
# questions = defaultdict(dict)
|
||||
#
|
||||
# for q, n, a in answer["ans"]:
|
||||
# questions[q][n] = a
|
||||
# pass
|
||||
#
|
||||
# for qid in questions:
|
||||
# exiting_answers = CidUserAnswer.objects.filter(
|
||||
# question__id=qid, exam__id=answer["eid"], cid=answer["cid"]
|
||||
# )
|
||||
#
|
||||
# a = questions[qid]["a"]
|
||||
# b = questions[qid]["b"]
|
||||
# c = questions[qid]["c"]
|
||||
# d = questions[qid]["d"]
|
||||
# e = questions[qid]["e"]
|
||||
#
|
||||
# if not exiting_answers:
|
||||
# ans = CidUserAnswer(a=a, b=b, c=c, d=d, e=e, cid=answer["cid"])
|
||||
# ans.question_id = qid
|
||||
# ans.exam_id = answer["eid"]
|
||||
#
|
||||
# ans.full_clean()
|
||||
#
|
||||
# ans.save()
|
||||
# else:
|
||||
# # Update an existing answer
|
||||
# # should never be more than one (famous last words)
|
||||
# ans = exiting_answers[0]
|
||||
# ans.a = a
|
||||
# ans.b = b
|
||||
# ans.c = c
|
||||
# ans.d = d
|
||||
# ans.e = e
|
||||
# ans.full_clean()
|
||||
# ans.save()
|
||||
#
|
||||
# return True, None
|
||||
|
||||
|
||||
GenericExamViews = ExamViews(
|
||||
Exam, Question, None, CidUserAnswer, "physics", "physics", loadJsonAnswer
|
||||
Exam, Question, None, CidUserAnswer, "physics", "physics"
|
||||
)
|
||||
|
||||
GenericViews = GenericViewBase("physics", Question, CidUserAnswer, Exam)
|
||||
|
||||
Reference in New Issue
Block a user