From 01f00fc9c41a93f00ac35406cc668ce8ddde245b Mon Sep 17 00:00:00 2001 From: Ross Date: Sun, 1 Aug 2021 10:24:29 +0100 Subject: [PATCH] . --- generic/views.py | 2 +- longs/models.py | 25 +++++++++++++------------ longs/views.py | 6 +++--- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/generic/views.py b/generic/views.py index 5f55c409..3cade000 100644 --- a/generic/views.py +++ b/generic/views.py @@ -409,7 +409,7 @@ class ExamViews(View, LoginRequiredMixin): for question in exam.exam_questions.all(): # Generate json if needed if question.json_creation_time is None: - question.get_json(question.pk) + question.get_question_json() h[question.pk] = question.question_json_id obj["multi_question_json"] = h active_exams["exams"].append( obj ) diff --git a/longs/models.py b/longs/models.py index 9c3ea4ff..7f71c8bc 100644 --- a/longs/models.py +++ b/longs/models.py @@ -176,15 +176,16 @@ 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, based=True): + def get_question_json(self, based=True): # self == q? - q = get_object_or_404(Long, pk=question_id) + #q = get_object_or_404(Long, pk=question_id) + question_id = self.pk if not based: image_titles = [] images = [] - question_series = q.series.all() + question_series = self.series.all() # Loop through longimage associations for i, series in enumerate(question_series): #image_array = [] @@ -199,7 +200,7 @@ class Long(models.Model): image_titles.append(series.get_examination()) question_json = { - "title": q.history, + "title": self.history, "images": images, "image_titles": image_titles, #"feedback_image": [], @@ -215,9 +216,9 @@ class Long(models.Model): url= "{0}longs/questions/{1}.json".format(settings.MEDIA_URL, question_id) timestamp = timezone.now() - q.question_json_id += 1 + self.question_json_id += 1 - print("QID", q.question_json_id) + print("QID", self.question_json_id) with open(path, "w+") as f: @@ -227,7 +228,7 @@ class Long(models.Model): "type": "long", "generated": "{}", "question_json_id": "{}", - """.format(q.history, timestamp.isoformat(), q.question_json_id) + """.format(self.history, timestamp.isoformat(), self.question_json_id) ) @@ -235,7 +236,7 @@ class Long(models.Model): #images = [] image_titles = [] - question_series = q.series.all() + question_series = self.series.all() # Loop through longimage associations for i, series in enumerate(question_series): #image_array = [] @@ -255,10 +256,10 @@ class Long(models.Model): f.write('"image_titles" : {} }}'.format(json.dumps(image_titles))) - print("QID2", q.question_json_id) + print("QID2", self.question_json_id) - q.json_creation_time = timestamp - q.save() + self.json_creation_time = timestamp + self.save() #exam_question = { # "title": q.history, @@ -592,7 +593,7 @@ class Exam(ExamBase): # If it is a new question we need to for a question json refresh if q.json_creation_time is None: - q.get_json(q.pk) + q.get_question_json() exam_questions[q.id] = q.question_json_id else: diff --git a/longs/views.py b/longs/views.py index 31616fd8..8163532f 100755 --- a/longs/views.py +++ b/longs/views.py @@ -957,7 +957,7 @@ def question_json_unbased(request, pk): """ question = get_object_or_404(Long, pk=pk) - question_json = question.get_json(pk, based=False) + question_json = question.get_question_json(based=False) return JsonResponse(question_json) def question_json(request, pk): @@ -973,7 +973,7 @@ def question_json(request, pk): if os.path.isfile(path) and not question.recreate_json: return redirect(url) - question_json = question.get_json(pk) + question_json = question.get_question_json() question.recreate_json = False question.save() @@ -988,6 +988,6 @@ def question_json_recreate(request, pk): question.recreate_json = True question.save() - question.get_json(pk) + question.get_question_json() return redirect("longs:question_detail", pk=pk) \ No newline at end of file