From 8918f1cd5b8588cf26ae7d00ec23e647df2e080d Mon Sep 17 00:00:00 2001 From: Ross Date: Sun, 18 Apr 2021 12:03:07 +0100 Subject: [PATCH] . --- generic/views.py | 3 +++ longs/models.py | 32 +++++++++++++++++++++++++++++++- longs/urls.py | 1 + longs/views.py | 8 ++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/generic/views.py b/generic/views.py index 470a6976..f501816c 100644 --- a/generic/views.py +++ b/generic/views.py @@ -369,6 +369,9 @@ class ExamViews(View, LoginRequiredMixin): return JsonResponse({"success": False, "error": "Invalid data"}) def exam_json_unbased(self, request, pk): + """ + No (file based) caching is enabled for unbased exams + """ exam = get_object_or_404(self.Exam, pk=pk) if not exam.active: diff --git a/longs/models.py b/longs/models.py index 2e6ddc75..244a12e7 100644 --- a/longs/models.py +++ b/longs/models.py @@ -169,10 +169,40 @@ class Long(models.Model): answers = self.cid_user_answers.all() return [ans for ans in answers if not ans.is_marked()] - def get_json(self, question_id): + def get_json(self, question_id, based=True): # self == q? q = get_object_or_404(Long, pk=question_id) + + if not based: + image_titles = [] + images = [] + 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...) + images.append([i.image for i in series.images.all()]) + #image_array = [i.image.url for i in series.images.all()] + #images.append(url) + image_titles.append(series.get_examination()) + + question_json = { + "title": q.history, + "images": images, + "image_titles": image_titles, + #"feedback_image": [], + #"annotations": [str(q.image_annotations)], + "type": "long", + "cached": False, + } + return question_json + + #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) diff --git a/longs/urls.py b/longs/urls.py index f331d6ce..b43044eb 100755 --- a/longs/urls.py +++ b/longs/urls.py @@ -20,6 +20,7 @@ urlpatterns = [ # path("verified//", views.verified_detail, name="verified_detail"), path("question//", views.question_detail, name="question_detail"), path("question//json", views.question_json, name="question_json"), + path("question//json/unbased", views.question_json_unbased, name="question_json_unbased"), path("question//json/recreate", views.question_json_recreate, name="question_json_recreate"), path("question//split", views.long_split, name="long_split"), path("question//clone", views.LongClone.as_view(), name="long_clone"), diff --git a/longs/views.py b/longs/views.py index 28bf36be..afdeed3c 100755 --- a/longs/views.py +++ b/longs/views.py @@ -988,6 +988,14 @@ class ExamViewSet(viewsets.ModelViewSet): queryset = Exam.objects.all().order_by('name') serializer_class = ExamSerializer +def question_json_unbased(self, request, pk): + """ + No (file based) caching is enabled for unbased quesitons + """ + question = get_object_or_404(self.Exam, pk=pk) + + question_json = question.get_json(pk, based=False) + return JsonResponse(question_json) def question_json(request, pk): question = get_object_or_404(Long, pk=pk)