staging changes
This commit is contained in:
@@ -203,6 +203,7 @@ class ExamBase(models.Model):
|
|||||||
return authors
|
return authors
|
||||||
|
|
||||||
def check_cid_user(self, cid: int|None, passcode: str|None, request: HttpRequest|None=None, user_id: int|None=None, allow_authors: bool=True):
|
def check_cid_user(self, cid: int|None, passcode: str|None, request: HttpRequest|None=None, user_id: int|None=None, allow_authors: bool=True):
|
||||||
|
print(f"Check cid user: {cid=}, {passcode=}, exam_id={self.pk}")
|
||||||
if request is not None and request.user.is_superuser:
|
if request is not None and request.user.is_superuser:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
+10
-1
@@ -1704,13 +1704,22 @@ class ExamViews(View, LoginRequiredMixin):
|
|||||||
def exam_question_json_unbased_cid(self, request, pk, sk, cid, passcode):
|
def exam_question_json_unbased_cid(self, request, pk, sk, cid, passcode):
|
||||||
return self.exam_question_json_unbased(request, pk, sk, cid, passcode)
|
return self.exam_question_json_unbased(request, pk, sk, cid, passcode)
|
||||||
|
|
||||||
def exam_question_json_unbased(self, request, pk, sk):
|
def exam_question_json_unbased(self, request, pk, sk, cid=None, passcode=None):
|
||||||
question = get_object_or_404(self.Question, pk=sk)
|
question = get_object_or_404(self.Question, pk=sk)
|
||||||
exam = get_object_or_404(self.Exam, pk=pk)
|
exam = get_object_or_404(self.Exam, pk=pk)
|
||||||
|
|
||||||
if not exam.active and not self.check_user_access(request.user, pk):
|
if not exam.active and not self.check_user_access(request.user, pk):
|
||||||
raise Http404("No available exam")
|
raise Http404("No available exam")
|
||||||
|
|
||||||
|
# Check access for users
|
||||||
|
if request.user.is_anonymous:
|
||||||
|
user_id = None
|
||||||
|
else:
|
||||||
|
user_id = request.user.pk
|
||||||
|
if not exam.check_cid_user(cid, passcode, request, user_id):
|
||||||
|
raise Http404("No available exam")
|
||||||
|
|
||||||
|
|
||||||
return redirect("{}:question_json_unbased".format(self.app_name), pk=sk)
|
return redirect("{}:question_json_unbased".format(self.app_name), pk=sk)
|
||||||
redirect()
|
redirect()
|
||||||
|
|
||||||
|
|||||||
+24
-3
@@ -213,9 +213,26 @@ class Long(models.Model):
|
|||||||
|
|
||||||
return marker_unmarked
|
return marker_unmarked
|
||||||
|
|
||||||
def get_question_json(self, based=True, feedback=False):
|
def get_question_model_answers(self):
|
||||||
# self == q?
|
"""Returns a dict of the question model answers"""
|
||||||
# q = get_object_or_404(Long, pk=question_id)
|
return {
|
||||||
|
"observations": self.model_observations,
|
||||||
|
"interpretation": self.model_interpretation,
|
||||||
|
"principle diagnosis": self.model_principle_diagnosis,
|
||||||
|
"differential_diagnosis": self.model_differential_diagnosis,
|
||||||
|
"management": self.model_management,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def get_question_json(self, based: bool=True, answers: bool=True, feedback: bool=False):
|
||||||
|
"""Returns a json representation of the question
|
||||||
|
|
||||||
|
if based = False return is a dict
|
||||||
|
otherwise a url to the json file
|
||||||
|
|
||||||
|
answers arg is only parsed if based = False
|
||||||
|
"""
|
||||||
|
|
||||||
question_id = self.pk
|
question_id = self.pk
|
||||||
|
|
||||||
if not based:
|
if not based:
|
||||||
@@ -249,6 +266,10 @@ class Long(models.Model):
|
|||||||
"type": "long",
|
"type": "long",
|
||||||
"cached": False,
|
"cached": False,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if answers:
|
||||||
|
question_json["answers"] = self.get_question_model_answers()
|
||||||
|
|
||||||
return question_json
|
return question_json
|
||||||
|
|
||||||
# exam_order.append(q.id)
|
# exam_order.append(q.id)
|
||||||
|
|||||||
Reference in New Issue
Block a user