This commit is contained in:
Ross
2021-02-27 09:17:15 +00:00
parent 863b03f168
commit 28ff5dc674
3 changed files with 66 additions and 8 deletions
+24
View File
@@ -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)