continue unifying views

This commit is contained in:
Ross
2021-02-07 22:43:17 +00:00
parent 3712cf15fc
commit 8fbb50ee9f
12 changed files with 330 additions and 752 deletions
+35
View File
@@ -15,6 +15,9 @@ import string
from generic.models import Examination, ExamBase
from collections import defaultdict
from helpers.images import image_as_base64
image_storage = FileSystemStorage(
# Physical file location ROOT
location=u"{0}/anatomy/".format(settings.MEDIA_ROOT),
@@ -273,6 +276,38 @@ class Exam(ExamBase):
help_text="Exam time limit (in seconds)", default=5400
)
def get_exam_json(self):
questions = self.exam_questions.all()
exam_questions = defaultdict(dict)
exam_order = []
for q in questions:
exam_order.append(q.id)
exam_questions[q.id] = {
"title": "{}".format(q.description),
"question": str(q.question_type),
"images": [image_as_base64(q.image)],
"annotations": [str(q.image_annotations)],
"type": "anatomy",
}
exam_json = {
"eid": "anatomy/{}".format(self.id),
"cached": False,
"exam_type": "anatomy",
"exam_name": self.name,
"exam_mode": True,
"exam_order": exam_order,
"questions": exam_questions,
}
if self.time_limit:
exam_json["exam_time"] = self.time_limit
return exam_json
# class UserAnswer(models.Model):