.
This commit is contained in:
@@ -16,6 +16,8 @@ from django.utils.html import mark_safe
|
||||
from sortedm2m.fields import SortedManyToManyField
|
||||
|
||||
import string
|
||||
from collections import defaultdict
|
||||
from helpers.images import image_as_base64
|
||||
|
||||
|
||||
from generic.models import Site, Condition, Sign, ExamBase
|
||||
@@ -350,6 +352,55 @@ class Exam(ExamBase):
|
||||
help_text="Exam time limit (in seconds). Default is 2100 secondse (35 minutes)", default=2100
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
# Loop through rapidimage associations
|
||||
images = []
|
||||
feedback_images = []
|
||||
for i in q.images.all():
|
||||
if i.feedback_image == True:
|
||||
feedback_images.append(image_as_base64(i.image))
|
||||
# feedback_images.append(i.image.url)
|
||||
else:
|
||||
images.append(image_as_base64(i.image))
|
||||
#images.append(i.image.url)
|
||||
|
||||
|
||||
|
||||
exam_questions[q.id] = {
|
||||
"images": images,
|
||||
#"feedback_image": [],
|
||||
#"annotations": [str(q.image_annotations)],
|
||||
"type": "rapid",
|
||||
}
|
||||
|
||||
#if feedback_images:
|
||||
# exam_questions[q.id]["feedback_image"] = feedback_images
|
||||
|
||||
|
||||
exam_json = {
|
||||
"eid": "rapid/{}".format(exam.id),
|
||||
"cached": False,
|
||||
"exam_type": "rapid",
|
||||
"exam_name": exam.name,
|
||||
"exam_mode": True,
|
||||
"exam_order": exam_order,
|
||||
"questions": exam_questions,
|
||||
}
|
||||
|
||||
if exam.time_limit:
|
||||
exam_json["exam_time"] = exam.time_limit
|
||||
|
||||
return
|
||||
|
||||
|
||||
class CidUserAnswer(models.Model):
|
||||
"""User answers by candidate"""
|
||||
|
||||
Reference in New Issue
Block a user