From d0eb6453b6ae340d167f27a0a6f54c29ec29b8f1 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 8 Mar 2021 11:43:19 +0000 Subject: [PATCH 01/43] . --- longs/models.py | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/longs/models.py b/longs/models.py index 2a9b87e4..c7fc639d 100644 --- a/longs/models.py +++ b/longs/models.py @@ -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 = [] - # 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()) + 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) + + # 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("]") From 56ae100b243765215c0be5a6ccb8cf1dc4c5e441 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 8 Mar 2021 11:44:41 +0000 Subject: [PATCH 02/43] . --- longs/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/longs/models.py b/longs/models.py index f1373745..23a45b81 100644 --- a/longs/models.py +++ b/longs/models.py @@ -122,7 +122,7 @@ 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) + #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}) From 56307710adf14286fcfcb38c7a80134db1c1435f Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 8 Mar 2021 11:46:26 +0000 Subject: [PATCH 03/43] . --- longs/models.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/longs/models.py b/longs/models.py index 23a45b81..8755631c 100644 --- a/longs/models.py +++ b/longs/models.py @@ -49,9 +49,6 @@ 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 @@ -173,7 +170,8 @@ 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: + path=u"{0}longs/questions/{1}".format(settings.MEDIA_ROOT, question_id), + with open(path, "w") as f: # Loop through longimage associations f.write("[") images = [] From 4927ac1e889357c8b9c42a7308ee0325a0648b5e Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 8 Mar 2021 11:47:12 +0000 Subject: [PATCH 04/43] . --- longs/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/longs/models.py b/longs/models.py index 8755631c..ec5b654b 100644 --- a/longs/models.py +++ b/longs/models.py @@ -170,7 +170,7 @@ class Long(models.Model): q = get_object_or_404(Long, pk=question_id) #exam_order.append(q.id) - path=u"{0}longs/questions/{1}".format(settings.MEDIA_ROOT, question_id), + path= "{0}longs/questions/{1}".format(settings.MEDIA_ROOT, question_id) with open(path, "w") as f: # Loop through longimage associations f.write("[") From 234339b0bdbbe6960fc2e7e0157acdbc4ae8621e Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 8 Mar 2021 11:48:16 +0000 Subject: [PATCH 05/43] . --- longs/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/longs/models.py b/longs/models.py index ec5b654b..b901c21d 100644 --- a/longs/models.py +++ b/longs/models.py @@ -171,7 +171,7 @@ class Long(models.Model): #exam_order.append(q.id) path= "{0}longs/questions/{1}".format(settings.MEDIA_ROOT, question_id) - with open(path, "w") as f: + with open(path, "w+") as f: # Loop through longimage associations f.write("[") images = [] From 007db4b9a2146a75cb19b87a7fd3db68a41d23db Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 8 Mar 2021 11:51:12 +0000 Subject: [PATCH 06/43] . --- longs/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/longs/models.py b/longs/models.py index b901c21d..77d40c47 100644 --- a/longs/models.py +++ b/longs/models.py @@ -186,7 +186,7 @@ class Long(models.Model): # 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()] + image_array = [i.image.url for i in series.images.all()] f.write(json.dumps(image_array)) #images.append(image_array) if i != len(question_series) - 1: From d9b919a588287c44376543d1ae8d16d42fdbeadd Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 8 Mar 2021 11:55:08 +0000 Subject: [PATCH 07/43] . --- longs/models.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/longs/models.py b/longs/models.py index 77d40c47..2d6cc589 100644 --- a/longs/models.py +++ b/longs/models.py @@ -170,7 +170,8 @@ class Long(models.Model): q = get_object_or_404(Long, pk=question_id) #exam_order.append(q.id) - path= "{0}longs/questions/{1}".format(settings.MEDIA_ROOT, question_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) with open(path, "w+") as f: # Loop through longimage associations f.write("[") @@ -185,10 +186,10 @@ class Long(models.Model): # #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()] + 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(image_array) + images.append(url) if i != len(question_series) - 1: f.write(",") image_titles.append(series.get_examination()) From 3426257bf439e9e58c55893f056c28d3dc222be1 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 8 Mar 2021 12:21:25 +0000 Subject: [PATCH 08/43] . --- longs/models.py | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/longs/models.py b/longs/models.py index 2d6cc589..301e6406 100644 --- a/longs/models.py +++ b/longs/models.py @@ -35,6 +35,7 @@ from easy_thumbnails.files import get_thumbnailer from easy_thumbnails.exceptions import InvalidImageFormatError import pydicom +import datetime @@ -173,12 +174,22 @@ class Long(models.Model): path= "{0}longs/questions/{1}.json".format(settings.MEDIA_ROOT, question_id) url= "{0}longs/questions/{1}.json".format(settings.MEDIA_URL, question_id) with open(path, "w+") as f: - # Loop through longimage associations - f.write("[") - images = [] + + f.write(""" + "title": {}, + "image_titles": {}, + "type": "long", + "generated": "long", + """.format(q.history, datetime.datetime.now.isoformat()) + ) + + + 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(): @@ -189,25 +200,27 @@ class Long(models.Model): 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) + #images.append(url) if i != len(question_series) - 1: f.write(",") image_titles.append(series.get_examination()) - f.write("]") + f.write("],") + + f.write("'image_titles' : {} }".format(json.dumps(image_titles))) - exam_question = { - "title": q.history, - "images": images, - "image_titles": image_titles, - #"feedback_image": [], - #"annotations": [str(q.image_annotations)], - "type": "long", - "cached": False, - } + #exam_question = { + # "title": q.history, + # "images": images, + # "image_titles": image_titles, + # #"feedback_image": [], + # #"annotations": [str(q.image_annotations)], + # "type": "long", + # "cached": False, + #} - return exam_question + return url @@ -497,6 +510,7 @@ class Exam(ExamBase): #"feedback_image": [], #"annotations": [str(q.image_annotations)], "type": "long", + "images_json": True, } return exam_question From 2c7e4aa1adc419e7787140c6539045d1aff121cc Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 8 Mar 2021 12:22:23 +0000 Subject: [PATCH 09/43] . --- longs/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/longs/models.py b/longs/models.py index 301e6406..0bfa3ade 100644 --- a/longs/models.py +++ b/longs/models.py @@ -180,7 +180,7 @@ class Long(models.Model): "image_titles": {}, "type": "long", "generated": "long", - """.format(q.history, datetime.datetime.now.isoformat()) + """.format(q.history, datetime.datetime.now().isoformat()) ) From 1bed3035e4574bae2b2f361467e3c50bc50cbb6b Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 8 Mar 2021 12:23:54 +0000 Subject: [PATCH 10/43] . --- longs/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/longs/models.py b/longs/models.py index 0bfa3ade..b47bdb15 100644 --- a/longs/models.py +++ b/longs/models.py @@ -206,7 +206,7 @@ class Long(models.Model): image_titles.append(series.get_examination()) f.write("],") - f.write("'image_titles' : {} }".format(json.dumps(image_titles))) + f.write("'image_titles' : {} }}".format(json.dumps(image_titles))) From c7c0cc514c7faa487654651a1557fe52a490aefe Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 8 Mar 2021 12:26:28 +0000 Subject: [PATCH 11/43] . --- longs/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/longs/views.py b/longs/views.py index bb82ac6f..9c94b2c0 100755 --- a/longs/views.py +++ b/longs/views.py @@ -996,8 +996,8 @@ def question_json(request, pk): question_json_cache = cache.get("{}_question_json_{}".format("longs", pk)) if question_json_cache is not None and not question.recreate_json: - question_json_cache["cached"] = True - return JsonResponse(question_json_cache) + #question_json_cache["cached"] = True + return question_json_cache question_json = question.get_json(pk) @@ -1006,7 +1006,7 @@ def question_json(request, pk): question.recreate_json = False question.save() - return JsonResponse(question_json) + return question_json @login_required def question_json_recreate(request, pk): From f1295f4eb0762cb9cd8829dae0d324bd1494b048 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 8 Mar 2021 12:30:52 +0000 Subject: [PATCH 12/43] . --- longs/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/longs/views.py b/longs/views.py index 9c94b2c0..a63b372b 100755 --- a/longs/views.py +++ b/longs/views.py @@ -997,7 +997,7 @@ def question_json(request, pk): if question_json_cache is not None and not question.recreate_json: #question_json_cache["cached"] = True - return question_json_cache + return redirect(question_json_cache) question_json = question.get_json(pk) @@ -1006,7 +1006,7 @@ def question_json(request, pk): question.recreate_json = False question.save() - return question_json + return redirect(question_json) @login_required def question_json_recreate(request, pk): From 236a26934d38765a9365d2b17b942fcc017de72d Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 8 Mar 2021 12:37:07 +0000 Subject: [PATCH 13/43] . --- generic/views.py | 3 +++ longs/models.py | 1 + 2 files changed, 4 insertions(+) diff --git a/generic/views.py b/generic/views.py index c96c7dda..a0d5d5a9 100644 --- a/generic/views.py +++ b/generic/views.py @@ -384,6 +384,9 @@ class ExamViews(View, LoginRequiredMixin): if not exam.active: raise Http404("No available exam") + return redirect("{}:question_json".format(self.app_name), pk=sk) + redirect() + question_json_cache = cache.get("{}_question_json_{}".format(self.app_name, sk)) if question_json_cache is not None and not question.recreate_json: diff --git a/longs/models.py b/longs/models.py index b47bdb15..80f08ceb 100644 --- a/longs/models.py +++ b/longs/models.py @@ -176,6 +176,7 @@ class Long(models.Model): with open(path, "w+") as f: f.write(""" + {{ "title": {}, "image_titles": {}, "type": "long", From 6071efef97c0cb4c2535cf4c36f5247d2f3d12ca Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 8 Mar 2021 13:44:10 +0000 Subject: [PATCH 14/43] . --- longs/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/longs/models.py b/longs/models.py index 80f08ceb..ce6c1212 100644 --- a/longs/models.py +++ b/longs/models.py @@ -198,8 +198,8 @@ class Long(models.Model): # #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()] + #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: From 2f66c6594ba47f1e3f7426ba966c1387af5b5452 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 8 Mar 2021 13:45:21 +0000 Subject: [PATCH 15/43] . --- longs/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/longs/models.py b/longs/models.py index ce6c1212..72d4e5ad 100644 --- a/longs/models.py +++ b/longs/models.py @@ -177,8 +177,8 @@ class Long(models.Model): f.write(""" {{ - "title": {}, - "image_titles": {}, + "title": "{}", + "image_titles": "{}", "type": "long", "generated": "long", """.format(q.history, datetime.datetime.now().isoformat()) From 3dce24a5e992632d27223cd4be557cd0ae7c1f91 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 8 Mar 2021 13:46:48 +0000 Subject: [PATCH 16/43] . --- longs/models.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/longs/models.py b/longs/models.py index 72d4e5ad..4d6316f3 100644 --- a/longs/models.py +++ b/longs/models.py @@ -175,8 +175,7 @@ class Long(models.Model): url= "{0}longs/questions/{1}.json".format(settings.MEDIA_URL, question_id) with open(path, "w+") as f: - f.write(""" - {{ + f.write("""{{ "title": "{}", "image_titles": "{}", "type": "long", @@ -198,8 +197,8 @@ class Long(models.Model): # #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()] + 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: From 6b2c7a1a8003e8bc0d8d9f0080930d5d8d4148e6 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 8 Mar 2021 13:49:16 +0000 Subject: [PATCH 17/43] . --- longs/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/longs/models.py b/longs/models.py index 4d6316f3..172d4cc6 100644 --- a/longs/models.py +++ b/longs/models.py @@ -206,7 +206,7 @@ class Long(models.Model): image_titles.append(series.get_examination()) f.write("],") - f.write("'image_titles' : {} }}".format(json.dumps(image_titles))) + f.write('"image_titles" : {} }}'.format(json.dumps(image_titles))) From f0efcd0c321842fceaf61b8f0a88c85694a59d47 Mon Sep 17 00:00:00 2001 From: Ross Date: Tue, 9 Mar 2021 15:18:19 +0000 Subject: [PATCH 18/43] . --- generic/models.py | 2 ++ generic/views.py | 32 +++++++++++++++++++++++++------- longs/models.py | 8 ++++++-- rapids/forms.py | 2 +- 4 files changed, 34 insertions(+), 10 deletions(-) diff --git a/generic/models.py b/generic/models.py index b812654c..732c6352 100644 --- a/generic/models.py +++ b/generic/models.py @@ -64,6 +64,8 @@ class ExamBase(models.Model): help_text="If the json cache needs updating", default=False ) + json_creation_time = models.DateTimeField(blank=True) + #time_limit = models.IntegerField( # help_text="Exam time limit (in seconds). Default is 2100 secondse (35 minutes)", # default=2100, diff --git a/generic/views.py b/generic/views.py index a0d5d5a9..e55e39a8 100644 --- a/generic/views.py +++ b/generic/views.py @@ -32,6 +32,10 @@ from anatomy.models import AnatomyQuestion as AnatomyQuestion from anatomy.models import Exam as AnatomyExam from django.db.models import Case, When +from django.conf import settings + +from datetime import datetime +import os # Create your views here. @@ -320,6 +324,8 @@ class ExamViews(View, LoginRequiredMixin): "name": exam.get_exam_name(), "url": request.build_absolute_uri(exam.get_json_url()), "type": self.question_type, + "eid": "{}/{}".format(self.question_type, exam.pk), + "json_creation_time": exam.json_creation_time.isoformat() } ) @@ -356,24 +362,36 @@ class ExamViews(View, LoginRequiredMixin): if not exam.active: raise Http404("No available exam") + exam_json_cache = cache.get("{}_exam_json_{}".format(self.app_name, pk)) - if exam_json_cache is not None and not exam.recreate_json: - exam_json_cache["cached"] = True + path= "{0}{1}/exam/{2}.json".format(settings.MEDIA_ROOT, self.app_name, pk) + url= "{0}{1}/exam/{2}.json".format(settings.MEDIA_URL, self.app_name, pk) + + + if os.path.isfile(path) and not exam.recreate_json: + #exam_json_cache["cached"] = True + return redirect(url) return JsonResponse(exam_json_cache) - exam_json = exam.get_exam_json() + + with open(path, "w+") as f: + exam_json = exam.get_exam_json() + exam_json["generated"] = datetime.now().isoformat() + f.write(json.dumps(exam_json)) exam.recreate_json = False + + exam.json_creation_time = datetime.now() exam.save() # We also try to clear the cache of any associated questions (longs) # see exam_question_json - n = exam.exam_questions.count() - question_keys = ["{}_exam_json_{}_{}".format(self.app_name, pk, i) for i in range(1, n)] - cache.delete_many(question_keys) + #n = exam.exam_questions.count() + #question_keys = ["{}_exam_json_{}_{}".format(self.app_name, pk, i) for i in range(1, n)] + #cache.delete_many(question_keys) - cache.set("{}_exam_json_{}".format(self.app_name, pk), exam_json, 3600) + #cache.set("{}_exam_json_{}".format(self.app_name, pk), exam_json, 3600) return JsonResponse(exam_json) diff --git a/longs/models.py b/longs/models.py index 172d4cc6..bb71b396 100644 --- a/longs/models.py +++ b/longs/models.py @@ -120,6 +120,8 @@ class Long(models.Model): help_text="If the json cache needs updating", default=False ) + json_creation_time = models.DateTimeField(blank=True) + #question_file = models.FileField(upload_to=question_file_directory_path, blank=True, null=True) def get_absolute_url(self): @@ -175,11 +177,11 @@ class Long(models.Model): url= "{0}longs/questions/{1}.json".format(settings.MEDIA_URL, question_id) with open(path, "w+") as f: + # We manually create the json for long questions to reducem memroy usade f.write("""{{ "title": "{}", - "image_titles": "{}", "type": "long", - "generated": "long", + "generated": "{}", """.format(q.history, datetime.datetime.now().isoformat()) ) @@ -209,6 +211,8 @@ class Long(models.Model): f.write('"image_titles" : {} }}'.format(json.dumps(image_titles))) + self.json_creation_time = datetime.datetime.now() + self.save() #exam_question = { # "title": q.history, diff --git a/rapids/forms.py b/rapids/forms.py index dafba32e..d37c1b4d 100755 --- a/rapids/forms.py +++ b/rapids/forms.py @@ -85,7 +85,7 @@ class RapidForm(ModelForm): def __init__(self, *args, **kwargs): if kwargs.get("instance"): - # We get the 'initial' keyword argument or initialize it + # We gexam_json_cache is not Noneet the 'initial' keyword argument or initialize it # as a dict if it didn't exist. initial = kwargs.setdefault("initial", {}) # The widget for a ModelMultipleChoiceField expects From 7846eff6a31a935007033296360ae3bd19f2f107 Mon Sep 17 00:00:00 2001 From: Ross Date: Tue, 9 Mar 2021 15:19:38 +0000 Subject: [PATCH 19/43] . --- rapids/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rapids/forms.py b/rapids/forms.py index d37c1b4d..dafba32e 100755 --- a/rapids/forms.py +++ b/rapids/forms.py @@ -85,7 +85,7 @@ class RapidForm(ModelForm): def __init__(self, *args, **kwargs): if kwargs.get("instance"): - # We gexam_json_cache is not Noneet the 'initial' keyword argument or initialize it + # We get the 'initial' keyword argument or initialize it # as a dict if it didn't exist. initial = kwargs.setdefault("initial", {}) # The widget for a ModelMultipleChoiceField expects From d5637a14024f720b837dfb33643e5ad8349e330a Mon Sep 17 00:00:00 2001 From: Ross Date: Tue, 9 Mar 2021 15:28:54 +0000 Subject: [PATCH 20/43] . --- .../0035_exam_json_creation_time.py | 18 +++++++++++++++ generic/models.py | 2 +- generic/views.py | 6 ++++- longs/migrations/0031_auto_20210309_1527.py | 23 +++++++++++++++++++ longs/models.py | 2 +- .../0004_exam_json_creation_time.py | 18 +++++++++++++++ .../0020_exam_json_creation_time.py | 18 +++++++++++++++ 7 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 anatomy/migrations/0035_exam_json_creation_time.py create mode 100644 longs/migrations/0031_auto_20210309_1527.py create mode 100644 physics/migrations/0004_exam_json_creation_time.py create mode 100644 rapids/migrations/0020_exam_json_creation_time.py diff --git a/anatomy/migrations/0035_exam_json_creation_time.py b/anatomy/migrations/0035_exam_json_creation_time.py new file mode 100644 index 00000000..2138b523 --- /dev/null +++ b/anatomy/migrations/0035_exam_json_creation_time.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.3 on 2021-03-09 15:27 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('anatomy', '0034_auto_20210215_1200'), + ] + + operations = [ + migrations.AddField( + model_name='exam', + name='json_creation_time', + field=models.DateTimeField(blank=True, default=None, null=True), + ), + ] diff --git a/generic/models.py b/generic/models.py index 732c6352..95ffdb55 100644 --- a/generic/models.py +++ b/generic/models.py @@ -64,7 +64,7 @@ class ExamBase(models.Model): help_text="If the json cache needs updating", default=False ) - json_creation_time = models.DateTimeField(blank=True) + json_creation_time = models.DateTimeField(blank=True, default=None, null=True) #time_limit = models.IntegerField( # help_text="Exam time limit (in seconds). Default is 2100 secondse (35 minutes)", diff --git a/generic/views.py b/generic/views.py index e55e39a8..a91e4378 100644 --- a/generic/views.py +++ b/generic/views.py @@ -319,13 +319,17 @@ class ExamViews(View, LoginRequiredMixin): for exam in exams: if exam.active: + if exam.json_creation_time: + creation_time = exam.json_creation_time.isoformat() + else: + creation_time = "None" active_exams["exams"].append( { "name": exam.get_exam_name(), "url": request.build_absolute_uri(exam.get_json_url()), "type": self.question_type, "eid": "{}/{}".format(self.question_type, exam.pk), - "json_creation_time": exam.json_creation_time.isoformat() + "json_creation_time": creation_time } ) diff --git a/longs/migrations/0031_auto_20210309_1527.py b/longs/migrations/0031_auto_20210309_1527.py new file mode 100644 index 00000000..9542159f --- /dev/null +++ b/longs/migrations/0031_auto_20210309_1527.py @@ -0,0 +1,23 @@ +# Generated by Django 3.1.3 on 2021-03-09 15:27 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('longs', '0030_long_recreate_json'), + ] + + operations = [ + migrations.AddField( + model_name='exam', + name='json_creation_time', + field=models.DateTimeField(blank=True, default=None, null=True), + ), + migrations.AddField( + model_name='long', + name='json_creation_time', + field=models.DateTimeField(blank=True, default=None, null=True), + ), + ] diff --git a/longs/models.py b/longs/models.py index bb71b396..baf8edef 100644 --- a/longs/models.py +++ b/longs/models.py @@ -120,7 +120,7 @@ class Long(models.Model): help_text="If the json cache needs updating", default=False ) - json_creation_time = models.DateTimeField(blank=True) + json_creation_time = models.DateTimeField(blank=True, default=None, null=True) #question_file = models.FileField(upload_to=question_file_directory_path, blank=True, null=True) diff --git a/physics/migrations/0004_exam_json_creation_time.py b/physics/migrations/0004_exam_json_creation_time.py new file mode 100644 index 00000000..72074042 --- /dev/null +++ b/physics/migrations/0004_exam_json_creation_time.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.3 on 2021-03-09 15:27 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('physics', '0003_auto_20201228_2235'), + ] + + operations = [ + migrations.AddField( + model_name='exam', + name='json_creation_time', + field=models.DateTimeField(blank=True, default=None, null=True), + ), + ] diff --git a/rapids/migrations/0020_exam_json_creation_time.py b/rapids/migrations/0020_exam_json_creation_time.py new file mode 100644 index 00000000..e7bb2656 --- /dev/null +++ b/rapids/migrations/0020_exam_json_creation_time.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.3 on 2021-03-09 15:27 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('rapids', '0019_auto_20210215_1203'), + ] + + operations = [ + migrations.AddField( + model_name='exam', + name='json_creation_time', + field=models.DateTimeField(blank=True, default=None, null=True), + ), + ] From 7d34733a5a8c60b4d0fdbd332bb7167670258501 Mon Sep 17 00:00:00 2001 From: Ross Date: Tue, 9 Mar 2021 21:21:39 +0000 Subject: [PATCH 21/43] . --- generic/views.py | 4 ++-- longs/models.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/generic/views.py b/generic/views.py index a91e4378..a0f04362 100644 --- a/generic/views.py +++ b/generic/views.py @@ -320,7 +320,7 @@ class ExamViews(View, LoginRequiredMixin): for exam in exams: if exam.active: if exam.json_creation_time: - creation_time = exam.json_creation_time.isoformat() + creation_time = exam.json_creation_time.timestamp() else: creation_time = "None" active_exams["exams"].append( @@ -381,7 +381,7 @@ class ExamViews(View, LoginRequiredMixin): with open(path, "w+") as f: exam_json = exam.get_exam_json() - exam_json["generated"] = datetime.now().isoformat() + exam_json["generated"] = datetime.now().timestamp() f.write(json.dumps(exam_json)) exam.recreate_json = False diff --git a/longs/models.py b/longs/models.py index baf8edef..3c13f76b 100644 --- a/longs/models.py +++ b/longs/models.py @@ -182,7 +182,7 @@ class Long(models.Model): "title": "{}", "type": "long", "generated": "{}", - """.format(q.history, datetime.datetime.now().isoformat()) + """.format(q.history, datetime.datetime.now().timestamp()) ) From 4f5cf5b5de852cb7d7ec5f11c095246880c776df Mon Sep 17 00:00:00 2001 From: Ross Date: Tue, 9 Mar 2021 21:24:50 +0000 Subject: [PATCH 22/43] . --- generic/views.py | 7 ++++--- longs/models.py | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/generic/views.py b/generic/views.py index a0f04362..73ab0a07 100644 --- a/generic/views.py +++ b/generic/views.py @@ -320,7 +320,7 @@ class ExamViews(View, LoginRequiredMixin): for exam in exams: if exam.active: if exam.json_creation_time: - creation_time = exam.json_creation_time.timestamp() + creation_time = exam.json_creation_time.isoformat() else: creation_time = "None" active_exams["exams"].append( @@ -378,15 +378,16 @@ class ExamViews(View, LoginRequiredMixin): return redirect(url) return JsonResponse(exam_json_cache) + time = datetime.now() with open(path, "w+") as f: exam_json = exam.get_exam_json() - exam_json["generated"] = datetime.now().timestamp() + exam_json["generated"] = time.isoformat() f.write(json.dumps(exam_json)) exam.recreate_json = False - exam.json_creation_time = datetime.now() + exam.json_creation_time = time exam.save() # We also try to clear the cache of any associated questions (longs) diff --git a/longs/models.py b/longs/models.py index 3c13f76b..89e04481 100644 --- a/longs/models.py +++ b/longs/models.py @@ -120,7 +120,7 @@ class Long(models.Model): help_text="If the json cache needs updating", default=False ) - json_creation_time = models.DateTimeField(blank=True, default=None, null=True) + json_creation_time = models.DateTimeField(blank=True, default=None) #question_file = models.FileField(upload_to=question_file_directory_path, blank=True, null=True) @@ -182,7 +182,7 @@ class Long(models.Model): "title": "{}", "type": "long", "generated": "{}", - """.format(q.history, datetime.datetime.now().timestamp()) + """.format(q.history, datetime.datetime.now().isoformat()) ) From 6b4a3f7479f6a4824acd3eaa096685ae6901ad87 Mon Sep 17 00:00:00 2001 From: Ross Date: Thu, 11 Mar 2021 12:51:53 +0000 Subject: [PATCH 23/43] . --- generic/views.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/generic/views.py b/generic/views.py index 73ab0a07..7e00a2a2 100644 --- a/generic/views.py +++ b/generic/views.py @@ -323,15 +323,21 @@ class ExamViews(View, LoginRequiredMixin): creation_time = exam.json_creation_time.isoformat() else: creation_time = "None" - active_exams["exams"].append( - { + + json = { "name": exam.get_exam_name(), "url": request.build_absolute_uri(exam.get_json_url()), "type": self.question_type, "eid": "{}/{}".format(self.question_type, exam.pk), "json_creation_time": creation_time } - ) + + if self.question_type == "long": + h = {} + for question in exam.questions.all(): + h[question.pk] = question.json_creation_time + json["multi_question_json"] = h + active_exams["exams"].append( json ) if json == False: return active_exams["exams"] From e23374678e8ab7069edea58be1ac947f6d21044b Mon Sep 17 00:00:00 2001 From: Ross Date: Thu, 11 Mar 2021 12:53:49 +0000 Subject: [PATCH 24/43] . --- generic/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generic/views.py b/generic/views.py index 7e00a2a2..7adfffee 100644 --- a/generic/views.py +++ b/generic/views.py @@ -334,7 +334,7 @@ class ExamViews(View, LoginRequiredMixin): if self.question_type == "long": h = {} - for question in exam.questions.all(): + for question in exam.exam_questions.all(): h[question.pk] = question.json_creation_time json["multi_question_json"] = h active_exams["exams"].append( json ) From fc87a255165e1d817b3f839edd2b49dea890fd11 Mon Sep 17 00:00:00 2001 From: Ross Date: Thu, 11 Mar 2021 12:54:42 +0000 Subject: [PATCH 25/43] . --- generic/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generic/views.py b/generic/views.py index 7adfffee..2e39cbc7 100644 --- a/generic/views.py +++ b/generic/views.py @@ -335,7 +335,7 @@ class ExamViews(View, LoginRequiredMixin): if self.question_type == "long": h = {} for question in exam.exam_questions.all(): - h[question.pk] = question.json_creation_time + h[question.pk] = question.json_creation_time.isoformat() json["multi_question_json"] = h active_exams["exams"].append( json ) From 5c0e0c42787be75eb021a21f4b14bd2d9f38a125 Mon Sep 17 00:00:00 2001 From: Ross Date: Thu, 11 Mar 2021 13:00:58 +0000 Subject: [PATCH 26/43] . --- generic/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generic/views.py b/generic/views.py index 2e39cbc7..ea8bfcba 100644 --- a/generic/views.py +++ b/generic/views.py @@ -336,7 +336,7 @@ class ExamViews(View, LoginRequiredMixin): h = {} for question in exam.exam_questions.all(): h[question.pk] = question.json_creation_time.isoformat() - json["multi_question_json"] = h + json["multi_question_json"] = "TEST" active_exams["exams"].append( json ) if json == False: From 4b621bf4e24dc3df9dc35daf6b097463d0c7970b Mon Sep 17 00:00:00 2001 From: Ross Date: Thu, 11 Mar 2021 13:01:58 +0000 Subject: [PATCH 27/43] . --- generic/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/generic/views.py b/generic/views.py index ea8bfcba..931b7956 100644 --- a/generic/views.py +++ b/generic/views.py @@ -336,7 +336,8 @@ class ExamViews(View, LoginRequiredMixin): h = {} for question in exam.exam_questions.all(): h[question.pk] = question.json_creation_time.isoformat() - json["multi_question_json"] = "TEST" + h[question.pk] = "TEST" + json["multi_question_json"] = h active_exams["exams"].append( json ) if json == False: From 076462a44dafc8b4e76f7fc7bba2a4ac597acc29 Mon Sep 17 00:00:00 2001 From: Ross Date: Thu, 11 Mar 2021 13:02:45 +0000 Subject: [PATCH 28/43] . --- generic/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/generic/views.py b/generic/views.py index 931b7956..bf0e0a71 100644 --- a/generic/views.py +++ b/generic/views.py @@ -334,9 +334,9 @@ class ExamViews(View, LoginRequiredMixin): if self.question_type == "long": h = {} - for question in exam.exam_questions.all(): - h[question.pk] = question.json_creation_time.isoformat() - h[question.pk] = "TEST" + #for question in exam.exam_questions.all(): + # h[question.pk] = question.json_creation_time.isoformat() + # h[question.pk] = "TEST" json["multi_question_json"] = h active_exams["exams"].append( json ) From 917edf875f0d37d9bcd30e41726781113b607796 Mon Sep 17 00:00:00 2001 From: Ross Date: Thu, 11 Mar 2021 13:03:28 +0000 Subject: [PATCH 29/43] . --- generic/views.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/generic/views.py b/generic/views.py index bf0e0a71..ce65b383 100644 --- a/generic/views.py +++ b/generic/views.py @@ -332,12 +332,12 @@ class ExamViews(View, LoginRequiredMixin): "json_creation_time": creation_time } - if self.question_type == "long": - h = {} - #for question in exam.exam_questions.all(): - # h[question.pk] = question.json_creation_time.isoformat() - # h[question.pk] = "TEST" - json["multi_question_json"] = h + #if self.question_type == "long": + # h = {} + # #for question in exam.exam_questions.all(): + # # h[question.pk] = question.json_creation_time.isoformat() + # # h[question.pk] = "TEST" + # json["multi_question_json"] = h active_exams["exams"].append( json ) if json == False: From 5327877aae8a33385b445d53c008976fc6a5102e Mon Sep 17 00:00:00 2001 From: Ross Date: Thu, 11 Mar 2021 13:05:03 +0000 Subject: [PATCH 30/43] . --- generic/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/generic/views.py b/generic/views.py index ce65b383..c97e26d4 100644 --- a/generic/views.py +++ b/generic/views.py @@ -324,7 +324,7 @@ class ExamViews(View, LoginRequiredMixin): else: creation_time = "None" - json = { + obj = { "name": exam.get_exam_name(), "url": request.build_absolute_uri(exam.get_json_url()), "type": self.question_type, @@ -338,7 +338,7 @@ class ExamViews(View, LoginRequiredMixin): # # h[question.pk] = question.json_creation_time.isoformat() # # h[question.pk] = "TEST" # json["multi_question_json"] = h - active_exams["exams"].append( json ) + active_exams["exams"].append( obj ) if json == False: return active_exams["exams"] From b96b88d2e5a208cbd1ec04c929e4a8fa1c55e326 Mon Sep 17 00:00:00 2001 From: Ross Date: Thu, 11 Mar 2021 13:05:29 +0000 Subject: [PATCH 31/43] . --- generic/views.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/generic/views.py b/generic/views.py index c97e26d4..56d30616 100644 --- a/generic/views.py +++ b/generic/views.py @@ -332,12 +332,11 @@ class ExamViews(View, LoginRequiredMixin): "json_creation_time": creation_time } - #if self.question_type == "long": - # h = {} - # #for question in exam.exam_questions.all(): - # # h[question.pk] = question.json_creation_time.isoformat() - # # h[question.pk] = "TEST" - # json["multi_question_json"] = h + if self.question_type == "long": + h = {} + for question in exam.exam_questions.all(): + h[question.pk] = question.json_creation_time.isoformat() + json["multi_question_json"] = h active_exams["exams"].append( obj ) if json == False: From cbcaa35bee09f7bcdd84d334d556e6f0e8eb33a9 Mon Sep 17 00:00:00 2001 From: Ross Date: Thu, 11 Mar 2021 13:05:57 +0000 Subject: [PATCH 32/43] . --- generic/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generic/views.py b/generic/views.py index 56d30616..b7452aae 100644 --- a/generic/views.py +++ b/generic/views.py @@ -336,7 +336,7 @@ class ExamViews(View, LoginRequiredMixin): h = {} for question in exam.exam_questions.all(): h[question.pk] = question.json_creation_time.isoformat() - json["multi_question_json"] = h + obj["multi_question_json"] = h active_exams["exams"].append( obj ) if json == False: From e5ebc41d5ea51f3324846431975b72d2e3ac0afc Mon Sep 17 00:00:00 2001 From: Ross Date: Thu, 11 Mar 2021 13:48:06 +0000 Subject: [PATCH 33/43] . --- longs/templates/longs/long_display_block.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/longs/templates/longs/long_display_block.html b/longs/templates/longs/long_display_block.html index b486ac91..19129b07 100755 --- a/longs/templates/longs/long_display_block.html +++ b/longs/templates/longs/long_display_block.html @@ -53,5 +53,8 @@ +
+ JSON creation time: {{question.json_creation_time}} +
JSON Refresh JSON cache \ No newline at end of file From 926f5e1d6d22e0bbe8b80b306976cc6ca8b47f9b Mon Sep 17 00:00:00 2001 From: Ross Date: Thu, 11 Mar 2021 13:49:28 +0000 Subject: [PATCH 34/43] . --- longs/templates/longs/long_display_block.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/longs/templates/longs/long_display_block.html b/longs/templates/longs/long_display_block.html index 19129b07..49771d4b 100755 --- a/longs/templates/longs/long_display_block.html +++ b/longs/templates/longs/long_display_block.html @@ -54,7 +54,7 @@
- JSON creation time: {{question.json_creation_time}} + JSON creation time: {{question.json_creation_time}} ({{question.json_creation_time|date:"c"}})
JSON Refresh JSON cache \ No newline at end of file From ccd72e987d128ea16165b475b9100c00e6dc7e6f Mon Sep 17 00:00:00 2001 From: Ross Date: Thu, 11 Mar 2021 14:07:36 +0000 Subject: [PATCH 35/43] . --- longs/models.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/longs/models.py b/longs/models.py index 89e04481..74962d94 100644 --- a/longs/models.py +++ b/longs/models.py @@ -175,6 +175,8 @@ class Long(models.Model): #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) + + timestamp = datetime.datetime.now() with open(path, "w+") as f: # We manually create the json for long questions to reducem memroy usade @@ -182,7 +184,7 @@ class Long(models.Model): "title": "{}", "type": "long", "generated": "{}", - """.format(q.history, datetime.datetime.now().isoformat()) + """.format(q.history, timestamp.isoformat()) ) @@ -211,7 +213,7 @@ class Long(models.Model): f.write('"image_titles" : {} }}'.format(json.dumps(image_titles))) - self.json_creation_time = datetime.datetime.now() + self.json_creation_time = timestamp self.save() #exam_question = { From bf29e0d3943cf5273bb9146a4332584823f3a33b Mon Sep 17 00:00:00 2001 From: Ross Date: Fri, 12 Mar 2021 08:55:48 +0000 Subject: [PATCH 36/43] . --- longs/views.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/longs/views.py b/longs/views.py index a63b372b..50d57252 100755 --- a/longs/views.py +++ b/longs/views.py @@ -993,16 +993,16 @@ def question_json(request, pk): #if not exam.active: # raise Http404("No available exam") - question_json_cache = cache.get("{}_question_json_{}".format("longs", pk)) + path= "{0}longs/questions/{1}.json".format(settings.MEDIA_ROOT, question_id) + url= "{0}{1}/exam/{2}.json".format(settings.MEDIA_URL, self.app_name, pk) + + if os.path.isfile(path) and not exam.recreate_json: if question_json_cache is not None and not question.recreate_json: - #question_json_cache["cached"] = True - return redirect(question_json_cache) + return redirect(url) question_json = question.get_json(pk) - cache.set("{}_question_json_{}".format("longs", pk), question_json, 3600) - question.recreate_json = False question.save() From 679c4ee90fb97bd08e879a9b8a9d24115db80d52 Mon Sep 17 00:00:00 2001 From: Ross Date: Fri, 12 Mar 2021 08:57:35 +0000 Subject: [PATCH 37/43] . --- longs/views.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/longs/views.py b/longs/views.py index 50d57252..2f8d127e 100755 --- a/longs/views.py +++ b/longs/views.py @@ -47,6 +47,7 @@ import statistics import plotly.express as px from django.core.cache import cache +from django.conf import settings from helpers.images import image_as_base64 @@ -996,9 +997,7 @@ def question_json(request, pk): path= "{0}longs/questions/{1}.json".format(settings.MEDIA_ROOT, question_id) url= "{0}{1}/exam/{2}.json".format(settings.MEDIA_URL, self.app_name, pk) - if os.path.isfile(path) and not exam.recreate_json: - - if question_json_cache is not None and not question.recreate_json: + if os.path.isfile(path) and not question.recreate_json: return redirect(url) question_json = question.get_json(pk) From 4c95be03f4dd0f5099b5b8064a7c2fb6c3311adc Mon Sep 17 00:00:00 2001 From: Ross Date: Fri, 12 Mar 2021 09:02:13 +0000 Subject: [PATCH 38/43] . --- generic/views.py | 2 +- longs/views.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/generic/views.py b/generic/views.py index b7452aae..53812c59 100644 --- a/generic/views.py +++ b/generic/views.py @@ -373,7 +373,7 @@ class ExamViews(View, LoginRequiredMixin): raise Http404("No available exam") - exam_json_cache = cache.get("{}_exam_json_{}".format(self.app_name, pk)) + #exam_json_cache = cache.get("{}_exam_json_{}".format(self.app_name, pk)) path= "{0}{1}/exam/{2}.json".format(settings.MEDIA_ROOT, self.app_name, pk) url= "{0}{1}/exam/{2}.json".format(settings.MEDIA_URL, self.app_name, pk) diff --git a/longs/views.py b/longs/views.py index 2f8d127e..40bddab4 100755 --- a/longs/views.py +++ b/longs/views.py @@ -994,8 +994,8 @@ def question_json(request, pk): #if not exam.active: # raise Http404("No available exam") - path= "{0}longs/questions/{1}.json".format(settings.MEDIA_ROOT, question_id) - url= "{0}{1}/exam/{2}.json".format(settings.MEDIA_URL, self.app_name, pk) + path= "{0}longs/questions/{1}.json".format(settings.MEDIA_ROOT, pk) + url= "{0}longs/questions/{1}.json".format(settings.MEDIA_URL, pk) if os.path.isfile(path) and not question.recreate_json: return redirect(url) From 0e4e24c2d9b3b04133b3aacffba3771e33fc1221 Mon Sep 17 00:00:00 2001 From: Ross Date: Fri, 12 Mar 2021 09:02:57 +0000 Subject: [PATCH 39/43] . --- longs/views.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/longs/views.py b/longs/views.py index 40bddab4..368ff741 100755 --- a/longs/views.py +++ b/longs/views.py @@ -64,6 +64,8 @@ from rest_framework import viewsets from .serializers import ExamSerializer +import os + logger = logging.getLogger(__name__) From 65a14e58c6c7e1c72728bc46daf20b6eea81186a Mon Sep 17 00:00:00 2001 From: Ross Date: Fri, 12 Mar 2021 10:40:44 +0000 Subject: [PATCH 40/43] . --- longs/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/longs/models.py b/longs/models.py index 74962d94..ca7472c7 100644 --- a/longs/models.py +++ b/longs/models.py @@ -533,7 +533,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 From af88f88d7f42c479108a4768b3ea5463fda5923b Mon Sep 17 00:00:00 2001 From: Ross Date: Fri, 12 Mar 2021 10:49:57 +0000 Subject: [PATCH 41/43] . --- generic/views.py | 2 ++ longs/models.py | 1 + longs/views.py | 2 ++ 3 files changed, 5 insertions(+) diff --git a/generic/views.py b/generic/views.py index 53812c59..f39b216e 100644 --- a/generic/views.py +++ b/generic/views.py @@ -181,6 +181,8 @@ class ExamViews(View, LoginRequiredMixin): exam.recreate_json = True exam.save() + exam.get_exam_json() + return redirect("{}:exam_overview".format(self.app_name), pk=pk) @method_decorator(login_required) diff --git a/longs/models.py b/longs/models.py index ca7472c7..826a9f22 100644 --- a/longs/models.py +++ b/longs/models.py @@ -170,6 +170,7 @@ 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) diff --git a/longs/views.py b/longs/views.py index 368ff741..f19a4b43 100755 --- a/longs/views.py +++ b/longs/views.py @@ -1016,4 +1016,6 @@ def question_json_recreate(request, pk): question.recreate_json = True question.save() + question.get_question_json(pk) + return redirect("longs:question_detail", pk=pk) \ No newline at end of file From 8136840ea51e5a96d69b2b5841d6f8ed9e92fb8a Mon Sep 17 00:00:00 2001 From: Ross Date: Fri, 12 Mar 2021 11:07:49 +0000 Subject: [PATCH 42/43] . --- longs/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/longs/models.py b/longs/models.py index 826a9f22..ff6c961b 100644 --- a/longs/models.py +++ b/longs/models.py @@ -574,7 +574,7 @@ class Exam(ExamBase): "exam_mode": True, "exam_order": exam_order, "questions": exam_questions, - "question_requests": True, + "question_requests": exam_questions, } From 16e3eaf42e7077c45a238b1ccf194b7b4f276888 Mon Sep 17 00:00:00 2001 From: Ross Date: Fri, 12 Mar 2021 11:21:34 +0000 Subject: [PATCH 43/43] . --- longs/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/longs/views.py b/longs/views.py index f19a4b43..28bf36be 100755 --- a/longs/views.py +++ b/longs/views.py @@ -1016,6 +1016,6 @@ def question_json_recreate(request, pk): question.recreate_json = True question.save() - question.get_question_json(pk) + question.get_json(pk) return redirect("longs:question_detail", pk=pk) \ No newline at end of file