.
This commit is contained in:
+1
-56
@@ -509,61 +509,6 @@ class RapidView(LoginRequiredMixin, SingleTableMixin, FilterView):
|
||||
filterset_class = RapidFilter
|
||||
|
||||
|
||||
def loadJsonAnswer(answer, cid, eid, uid):
|
||||
|
||||
exam = get_object_or_404(Exam, pk=eid)
|
||||
|
||||
if not exam.check_cid_user(cid, answer["passcode"], user_id=uid):
|
||||
return False, JsonResponse(
|
||||
{"success": False, "error": "invalid cid / passcode"}
|
||||
)
|
||||
|
||||
if uid:
|
||||
exiting_answers = CidUserAnswer.objects.filter(
|
||||
question__id=answer["qid"], exam__id=eid, user__id=uid
|
||||
)
|
||||
else:
|
||||
exiting_answers = CidUserAnswer.objects.filter(
|
||||
question__id=answer["qid"], exam__id=eid, cid=cid
|
||||
)
|
||||
|
||||
posted_answer = answer["ans"]
|
||||
|
||||
## qidn 1 does not hold answer data (but should always arrive prior to 2)
|
||||
# if answer["qidn"] == "1":
|
||||
# posted_answer = ""
|
||||
|
||||
# Normal answers are just posted with the answer "Normal"
|
||||
normal = False
|
||||
if posted_answer == "Normal":
|
||||
normal = True
|
||||
|
||||
if not exiting_answers:
|
||||
if uid:
|
||||
ans = CidUserAnswer(answer=posted_answer, normal=normal, user=User.objects.get(id=uid))
|
||||
else:
|
||||
ans = CidUserAnswer(answer=posted_answer, normal=normal, cid=cid)
|
||||
|
||||
ans.question_id = answer["qid"]
|
||||
ans.exam_id = eid
|
||||
|
||||
ans.full_clean()
|
||||
|
||||
ans.save()
|
||||
else:
|
||||
# Update an existing answer
|
||||
# should never be more than one (famous last words)
|
||||
ans = exiting_answers[0]
|
||||
if answer["qidn"] == "1":
|
||||
ans.normal = normal
|
||||
ans.answer = ""
|
||||
elif answer["qidn"] == "2" and not ans.normal:
|
||||
ans.answer = posted_answer
|
||||
ans.full_clean()
|
||||
ans.save()
|
||||
|
||||
return True, None
|
||||
|
||||
|
||||
@login_required
|
||||
def mark_all(request, exam_pk, sk):
|
||||
@@ -818,7 +763,7 @@ class QuestionDelete(AuthorOrCheckerRequiredMixin, DeleteView):
|
||||
|
||||
|
||||
GenericExamViews = ExamViews(
|
||||
Exam, Rapid, Answer, CidUserAnswer, "rapids", "rapid", loadJsonAnswer
|
||||
Exam, Rapid, Answer, CidUserAnswer, "rapids", "rapid"
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user