.
This commit is contained in:
+1
-70
@@ -615,75 +615,6 @@ class LongSeriesView(LoginRequiredMixin, SingleTableMixin, FilterView):
|
||||
filterset_class = LongSeriesFilter
|
||||
|
||||
|
||||
def loadJsonAnswer(answer):
|
||||
eid = int(answer["eid"].split("/")[1])
|
||||
cid = int(answer["cid"])
|
||||
|
||||
# As access is not restricted make sure the data appears valid
|
||||
if (not isinstance(cid, int)) or (
|
||||
not isinstance(eid, int) or (not isinstance(answer["ans"], str))
|
||||
):
|
||||
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 cid > max_int or eid > max_int:
|
||||
return False, JsonResponse({"success": False, "error": "invalid cid"})
|
||||
|
||||
exam = get_object_or_404(Exam, pk=eid)
|
||||
|
||||
if not exam.check_cid_user(cid, answer["passcode"]):
|
||||
return False, JsonResponse(
|
||||
{"success": False, "error": "invalid cid / passcode"}
|
||||
)
|
||||
|
||||
# if not exam.active:
|
||||
# return False, JsonResponse(
|
||||
# {"success": False, "error": "No active exam: {}".format(eid)}
|
||||
# )
|
||||
|
||||
exiting_answers = CidUserAnswer.objects.filter(
|
||||
question__id=answer["qid"], exam__id=eid, cid=cid
|
||||
)
|
||||
|
||||
posted_answer = answer["ans"]
|
||||
|
||||
# Long cases seperate sections by qidn
|
||||
qidn = answer["qidn"]
|
||||
|
||||
# If the user answer does not exist
|
||||
if not exiting_answers:
|
||||
ans = 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 = exiting_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()
|
||||
|
||||
return True, None
|
||||
|
||||
|
||||
@user_is_long_marker
|
||||
@reversion.create_revision()
|
||||
@@ -1178,7 +1109,7 @@ def long_series_order_upload_filename(request, pk):
|
||||
return redirect("longs:long_series_detail", pk=pk)
|
||||
|
||||
|
||||
GenericExamViews = ExamViews(Exam, Long, None, CidUserAnswer, "longs", "long", loadJsonAnswer)
|
||||
GenericExamViews = ExamViews(Exam, Long, None, CidUserAnswer, "longs", "long")
|
||||
|
||||
|
||||
class ExamCreate(RevisionMixin, LoginRequiredMixin, CreateView):
|
||||
|
||||
Reference in New Issue
Block a user