.
This commit is contained in:
@@ -358,6 +358,30 @@ class ExamViews(View, LoginRequiredMixin):
|
||||
exam.recreate_json = False
|
||||
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)
|
||||
|
||||
cache.set("{}_exam_json_{}".format(self.app_name, pk), exam_json, 3600)
|
||||
|
||||
return JsonResponse(exam_json)
|
||||
|
||||
def exam_question_json(self, request, pk, sk):
|
||||
exam = get_object_or_404(self.Exam, pk=pk)
|
||||
|
||||
if not exam.active:
|
||||
raise Http404("No available exam")
|
||||
|
||||
exam_json_cache = cache.get("{}_exam_json_{}_{}".format(self.app_name, pk, sk))
|
||||
|
||||
if exam_json_cache is not None and not exam.recreate_json:
|
||||
exam_json_cache["cached"] = True
|
||||
return JsonResponse(exam_json_cache)
|
||||
|
||||
exam_json = exam.get_exam_question_json()
|
||||
|
||||
cache.set("{}_exam_json_{}_{}".format(self.app_name, pk, sk), exam_json, 3600)
|
||||
|
||||
return JsonResponse(exam_json)
|
||||
+41
-8
@@ -417,6 +417,36 @@ class Exam(ExamBase):
|
||||
default=4500,
|
||||
)
|
||||
|
||||
def get_exam_question_json(self, n):
|
||||
q = self.exam_questions.all()[n]
|
||||
|
||||
#exam_order.append(q.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)
|
||||
images.append(image_array)
|
||||
image_titles.append(series.get_examination())
|
||||
|
||||
|
||||
|
||||
exam_question = {
|
||||
"title": q.history,
|
||||
"images": images,
|
||||
"image_titles": image_titles,
|
||||
#"feedback_image": [],
|
||||
#"annotations": [str(q.image_annotations)],
|
||||
"type": "long",
|
||||
}
|
||||
|
||||
return exam_question
|
||||
|
||||
|
||||
def get_exam_json(self):
|
||||
questions = self.exam_questions.all()
|
||||
|
||||
@@ -424,6 +454,7 @@ class Exam(ExamBase):
|
||||
|
||||
exam_order = []
|
||||
|
||||
n = 1
|
||||
for q in questions:
|
||||
exam_order.append(q.id)
|
||||
|
||||
@@ -439,15 +470,16 @@ class Exam(ExamBase):
|
||||
image_titles.append(series.get_examination())
|
||||
|
||||
|
||||
exam_questions[q.id] = n
|
||||
|
||||
exam_questions[q.id] = {
|
||||
"title": q.history,
|
||||
"images": images,
|
||||
"image_titles": image_titles,
|
||||
#"feedback_image": [],
|
||||
#"annotations": [str(q.image_annotations)],
|
||||
"type": "long",
|
||||
}
|
||||
#exam_questions[q.id] = {
|
||||
# "title": q.history,
|
||||
# "images": images,
|
||||
# "image_titles": image_titles,
|
||||
# #"feedback_image": [],
|
||||
# #"annotations": [str(q.image_annotations)],
|
||||
# "type": "long",
|
||||
#}
|
||||
|
||||
#if feedback_images:
|
||||
# exam_questions[q.id]["feedback_image"] = feedback_images
|
||||
@@ -461,6 +493,7 @@ class Exam(ExamBase):
|
||||
"exam_mode": True,
|
||||
"exam_order": exam_order,
|
||||
"questions": exam_questions,
|
||||
"question_requests": True,
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ urlpatterns = [
|
||||
path("exam/", views.LongExamViews.exam_list, name="exam_list"),
|
||||
path("exam/json/", views.LongExamViews.active_exams, name="active_exams"),
|
||||
path("exam/json/<int:pk>", views.LongExamViews.exam_json, name="exam_json"),
|
||||
path("exam/json/<int:pk>/<int:sk", views.LongExamViews.exam_question_json, name="exam_question_json"),
|
||||
path(
|
||||
"exam/json/<int:pk>/recreate",
|
||||
views.LongExamViews.exam_json_recreate,
|
||||
|
||||
Reference in New Issue
Block a user