staging changes

This commit is contained in:
Ross
2023-04-22 13:24:00 +01:00
parent 651a201bd4
commit cd5cbdd1a5
3 changed files with 35 additions and 4 deletions
+1
View File
@@ -203,6 +203,7 @@ class ExamBase(models.Model):
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):
print(f"Check cid user: {cid=}, {passcode=}, exam_id={self.pk}")
if request is not None and request.user.is_superuser:
return True
+10 -1
View File
@@ -1704,13 +1704,22 @@ class ExamViews(View, LoginRequiredMixin):
def exam_question_json_unbased_cid(self, 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)
exam = get_object_or_404(self.Exam, pk=pk)
if not exam.active and not self.check_user_access(request.user, pk):
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)
redirect()
+24 -3
View File
@@ -213,9 +213,26 @@ class Long(models.Model):
return marker_unmarked
def get_question_json(self, based=True, feedback=False):
# self == q?
# q = get_object_or_404(Long, pk=question_id)
def get_question_model_answers(self):
"""Returns a dict of the question model answers"""
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
if not based:
@@ -249,6 +266,10 @@ class Long(models.Model):
"type": "long",
"cached": False,
}
if answers:
question_json["answers"] = self.get_question_model_answers()
return question_json
# exam_order.append(q.id)