This commit is contained in:
Ross
2021-09-25 19:20:47 +01:00
parent c93e5d4a10
commit 0cb4294427
6 changed files with 280 additions and 92 deletions
+44 -1
View File
@@ -213,6 +213,49 @@ class AnatomyQuestion(models.Model):
def get_annotations(self):
return self.image_annotations
def get_title(self):
return "{}".format(self.description)
def get_correct_unstripped_answers(self):
return set(
[
str(i)
for i in self.answers.filter(proposed=False)
if i.status == i.MarkOptions.CORRECT
]
)
def get_question_json(self, based=True):
"""Returns a json representation of the question"""
# Loop through rapidimage associations
images = []
annotations = []
feedback_images = []
if based:
images.append(image_as_base64(self.image))
else:
images.append("{}/{}".format(settings.REMOTE_URL, self.image.url))
if self.image_annotations:
annotations.append(str(self.image_annotations))
json = {
"images": images,
#"feedback_image": [],
"annotations": annotations,
"type": "anatomy",
"title": self.get_title(),
"question": str(self.question_type),
}
json["answers"] = list(self.get_correct_unstripped_answers())
return json
@reversion.register
class Answer(models.Model):
@@ -313,7 +356,7 @@ class Exam(ExamBase):
exam_order.append(q.id)
exam_questions[q.id] = {
"title": "{}".format(q.description),
"title": q.get_title(),
"question": str(q.question_type),
"images": [image_as_base64(q.image)],
"annotations": [str(q.image_annotations)],