.
This commit is contained in:
+20
-4
@@ -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
|
||||
@@ -48,6 +49,9 @@ image_storage = FileSystemStorage(
|
||||
def image_directory_path(instance, filename):
|
||||
return u"longs/picture/{0}".format(filename)
|
||||
|
||||
def question_file_directory_path(instance, filename):
|
||||
return u"longs/question/{0}".format(filename)
|
||||
|
||||
|
||||
def findMiddle(input_list):
|
||||
middle = float(len(input_list)) / 2
|
||||
@@ -118,6 +122,8 @@ class Long(models.Model):
|
||||
help_text="If the json cache needs updating", default=False
|
||||
)
|
||||
|
||||
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})
|
||||
|
||||
@@ -167,18 +173,28 @@ class Long(models.Model):
|
||||
q = get_object_or_404(Long, pk=question_id)
|
||||
|
||||
#exam_order.append(q.id)
|
||||
|
||||
with open(question_file_directory_path(question_id), "w") as f:
|
||||
# Loop through longimage associations
|
||||
f.write("[")
|
||||
images = []
|
||||
image_titles = []
|
||||
for series in q.series.all():
|
||||
|
||||
question_series = q.series.all()
|
||||
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)
|
||||
image_array = [image_as_base64(i.image) for i in series.images.all()]
|
||||
images.append(image_array)
|
||||
|
||||
# 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 for i in series.images.all()]
|
||||
f.write(json.dumps(image_array))
|
||||
#images.append(image_array)
|
||||
if i != len(question_series) - 1:
|
||||
f.write(",")
|
||||
image_titles.append(series.get_examination())
|
||||
f.write("]")
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user