Merge branch 'master' of ssh://git.xkjq.uk:30001/ross/rad
This commit is contained in:
+60
-24
@@ -1,3 +1,4 @@
|
||||
import json
|
||||
from django.db.models.fields.files import ImageField
|
||||
from django.db.models.fields.related import ForeignKey
|
||||
from django.db import models
|
||||
@@ -34,6 +35,7 @@ from easy_thumbnails.files import get_thumbnailer
|
||||
from easy_thumbnails.exceptions import InvalidImageFormatError
|
||||
|
||||
import pydicom
|
||||
import datetime
|
||||
|
||||
|
||||
|
||||
@@ -118,6 +120,10 @@ class Long(models.Model):
|
||||
help_text="If the json cache needs updating", default=False
|
||||
)
|
||||
|
||||
json_creation_time = models.DateTimeField(blank=True, default=None)
|
||||
|
||||
#question_file = models.FileField(upload_to=question_file_directory_path, blank=True, null=True)
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse("longs:question_detail", kwargs={"pk": self.pk})
|
||||
|
||||
@@ -164,35 +170,64 @@ class Long(models.Model):
|
||||
return [ans for ans in answers if not ans.is_marked()]
|
||||
|
||||
def get_json(self, question_id):
|
||||
# self == q?
|
||||
q = get_object_or_404(Long, pk=question_id)
|
||||
|
||||
#exam_order.append(q.id)
|
||||
path= "{0}longs/questions/{1}.json".format(settings.MEDIA_ROOT, question_id)
|
||||
url= "{0}longs/questions/{1}.json".format(settings.MEDIA_URL, question_id)
|
||||
|
||||
# Loop through longimage associations
|
||||
images = []
|
||||
image_titles = []
|
||||
for series in q.series.all():
|
||||
#image_array = []
|
||||
#for i in series.images.all():
|
||||
# image_array.append(image_as_base64(i.image))
|
||||
# #image_array.append(i.image.url)
|
||||
image_array = [image_as_base64(i.image) for i in series.images.all()]
|
||||
images.append(image_array)
|
||||
image_titles.append(series.get_examination())
|
||||
timestamp = datetime.datetime.now()
|
||||
with open(path, "w+") as f:
|
||||
|
||||
|
||||
|
||||
exam_question = {
|
||||
"title": q.history,
|
||||
"images": images,
|
||||
"image_titles": image_titles,
|
||||
#"feedback_image": [],
|
||||
#"annotations": [str(q.image_annotations)],
|
||||
# We manually create the json for long questions to reducem memroy usade
|
||||
f.write("""{{
|
||||
"title": "{}",
|
||||
"type": "long",
|
||||
"cached": False,
|
||||
}
|
||||
"generated": "{}",
|
||||
""".format(q.history, timestamp.isoformat())
|
||||
)
|
||||
|
||||
return exam_question
|
||||
|
||||
f.write('"images" : [')
|
||||
#images = []
|
||||
image_titles = []
|
||||
|
||||
question_series = q.series.all()
|
||||
# Loop through longimage associations
|
||||
for i, series in enumerate(question_series):
|
||||
#image_array = []
|
||||
#for i in series.images.all():
|
||||
# image_array.append(image_as_base64(i.image))
|
||||
# #image_array.append(i.image.url)
|
||||
|
||||
# We are still limited by the size of a series (although this should not be too big or computers will crash...)
|
||||
image_array = [image_as_base64(i.image) for i in series.images.all()]
|
||||
#image_array = [i.image.url for i in series.images.all()]
|
||||
f.write(json.dumps(image_array))
|
||||
#images.append(url)
|
||||
if i != len(question_series) - 1:
|
||||
f.write(",")
|
||||
image_titles.append(series.get_examination())
|
||||
f.write("],")
|
||||
|
||||
f.write('"image_titles" : {} }}'.format(json.dumps(image_titles)))
|
||||
|
||||
|
||||
self.json_creation_time = timestamp
|
||||
self.save()
|
||||
|
||||
#exam_question = {
|
||||
# "title": q.history,
|
||||
# "images": images,
|
||||
# "image_titles": image_titles,
|
||||
# #"feedback_image": [],
|
||||
# #"annotations": [str(q.image_annotations)],
|
||||
# "type": "long",
|
||||
# "cached": False,
|
||||
#}
|
||||
|
||||
return url
|
||||
|
||||
|
||||
|
||||
@@ -482,6 +517,7 @@ class Exam(ExamBase):
|
||||
#"feedback_image": [],
|
||||
#"annotations": [str(q.image_annotations)],
|
||||
"type": "long",
|
||||
"images_json": True,
|
||||
}
|
||||
|
||||
return exam_question
|
||||
@@ -498,7 +534,7 @@ class Exam(ExamBase):
|
||||
for q in questions:
|
||||
exam_order.append(q.id)
|
||||
|
||||
exam_questions[q.id] = n
|
||||
exam_questions[q.id] = q.json_creation_time.isoformat()
|
||||
|
||||
continue
|
||||
|
||||
@@ -538,7 +574,7 @@ class Exam(ExamBase):
|
||||
"exam_mode": True,
|
||||
"exam_order": exam_order,
|
||||
"questions": exam_questions,
|
||||
"question_requests": True,
|
||||
"question_requests": exam_questions,
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user