.
This commit is contained in:
+96
-12
@@ -271,7 +271,6 @@ class ExamViews(View, LoginRequiredMixin):
|
||||
cid_user_answer,
|
||||
app,
|
||||
question_type,
|
||||
loadJsonAnswer,
|
||||
):
|
||||
self.Exam = exam
|
||||
self.Question = question
|
||||
@@ -279,7 +278,6 @@ class ExamViews(View, LoginRequiredMixin):
|
||||
self.CidUserAnswer = cid_user_answer
|
||||
self.app_name = app
|
||||
self.question_type = question_type
|
||||
self.loadJsonAnswer = loadJsonAnswer
|
||||
|
||||
# THis may be better than check_user_access below
|
||||
# group_map = {"rapids" : "rapid_checker", "anatomy" : "anatomy_checker", "longs":"long_checker"}
|
||||
@@ -1069,21 +1067,107 @@ class ExamViews(View, LoginRequiredMixin):
|
||||
{"success": False, "error": "cid or eid or answers not defined"}
|
||||
)
|
||||
|
||||
exam = get_object_or_404(self.Exam, pk=eid)
|
||||
|
||||
if not exam.check_cid_user(cid, answer["passcode"], user_id=uid):
|
||||
return JsonResponse(
|
||||
{"success": False, "error": "invalid cid / passcode"}
|
||||
)
|
||||
|
||||
if uid:
|
||||
existing_answers = self.CidUserAnswer.objects.filter(
|
||||
question__id=answer["qid"], exam__id=eid, user__id=uid
|
||||
)
|
||||
else:
|
||||
existing_answers = self.CidUserAnswer.objects.filter(
|
||||
question__id=answer["qid"], exam__id=eid, cid=cid
|
||||
)
|
||||
posted_answer = answer["ans"]
|
||||
|
||||
match self.app_name:
|
||||
case "rapids":
|
||||
|
||||
# Normal answers are just posted with the answer "Normal"
|
||||
normal = False
|
||||
if posted_answer == "Normal":
|
||||
normal = True
|
||||
|
||||
if not existing_answers:
|
||||
if uid:
|
||||
ans = self.CidUserAnswer(answer=posted_answer, normal=normal, user=User.objects.get(id=uid))
|
||||
else:
|
||||
ans = self.CidUserAnswer(answer=posted_answer, normal=normal, cid=cid)
|
||||
|
||||
ans.question_id = answer["qid"]
|
||||
ans.exam_id = eid
|
||||
else:
|
||||
# Update an existing answer
|
||||
# should never be more than one (famous last words)
|
||||
ans = existing_answers[0]
|
||||
if answer["qidn"] == "1":
|
||||
ans.normal = normal
|
||||
ans.answer = ""
|
||||
elif answer["qidn"] == "2" and not ans.normal:
|
||||
ans.answer = posted_answer
|
||||
case "anatomy":
|
||||
if not existing_answers:
|
||||
if uid:
|
||||
ans = self.CidUserAnswer(answer=posted_answer, uid=User.objects.get(id=uid))
|
||||
else:
|
||||
ans = self.CidUserAnswer(answer=posted_answer, cid=cid)
|
||||
|
||||
|
||||
ans.question_id = answer["qid"]
|
||||
ans.exam_id = eid
|
||||
ans.score = self.Answer.MarkOptions.UNMARKED
|
||||
else:
|
||||
# Update an existing answer
|
||||
# should never be more than one (famous last words)
|
||||
ans = existing_answers[0]
|
||||
ans.answer = posted_answer
|
||||
ans.score = self.Answer.MarkOptions.UNMARKED
|
||||
case "longs":
|
||||
# Long cases seperate sections by qidn
|
||||
qidn = answer["qidn"]
|
||||
|
||||
# If the user answer does not exist
|
||||
if not existing_answers:
|
||||
if uid:
|
||||
ans = self.CidUserAnswer(user=User.objects.get(id=uid))
|
||||
else:
|
||||
ans = self.CidUserAnswer(cid=cid)
|
||||
ans.question_id = answer["qid"]
|
||||
ans.exam_id = eid
|
||||
|
||||
# If the answer already exists or we have started populating it
|
||||
else:
|
||||
# Update an existing answer
|
||||
# should never be more than one (famous last words)
|
||||
ans = existing_answers[0]
|
||||
|
||||
if qidn == "1":
|
||||
ans.answer_observations = posted_answer
|
||||
elif qidn == "2":
|
||||
ans.answer_interpretation = posted_answer
|
||||
elif qidn == "3":
|
||||
ans.answer_principle_diagnosis = posted_answer
|
||||
elif qidn == "4":
|
||||
ans.answer_differential_diagnosis = posted_answer
|
||||
elif qidn == "5":
|
||||
ans.answer_management = posted_answer
|
||||
|
||||
# Mark as unmarked
|
||||
ans.score = ans.ScoreOptions.UNMARKED
|
||||
|
||||
ans.full_clean()
|
||||
ans.save()
|
||||
|
||||
|
||||
ret_status, ret = self.loadJsonAnswer(answer, cid=cid, eid=eid, uid=uid)
|
||||
# try:
|
||||
# ret_status, ret = self.loadJsonAnswer(answer)
|
||||
# except:
|
||||
# # We catch the error here so users get an error (rather than 500)
|
||||
# return JsonResponse({"success": False, "error": "Invalid data"})
|
||||
|
||||
# if ret is not True:
|
||||
# return ret
|
||||
|
||||
if ret_status:
|
||||
n = n + 1
|
||||
else:
|
||||
return ret
|
||||
n = n + 1
|
||||
|
||||
# print(UserAnswer.objects.filter(exam__id=q["eid"]))
|
||||
# print(request.urlencode())
|
||||
|
||||
Reference in New Issue
Block a user