This commit is contained in:
Ross
2021-03-01 08:25:00 +00:00
parent dd33a728de
commit 084b49df2e
2 changed files with 52 additions and 1 deletions
+21 -1
View File
@@ -966,4 +966,24 @@ LongExamViews = ExamViews(Exam, Long, "longs", "long", loadJsonAnswer)
class ExamViewSet(viewsets.ModelViewSet):
queryset = Exam.objects.all().order_by('name')
serializer_class = ExamSerializer
serializer_class = ExamSerializer
def question_json(self, request, pk):
question = get_object_or_404(self.Question, pk=pk)
#exam = get_object_or_404(self.Exam, pk=pk)
#if not exam.active:
# raise Http404("No available exam")
question_json_cache = cache.get("{}_question_json_{}".format("longs", sk))
if question_json_cache is not None and not question.recreate_json:
question_json_cache["cached"] = True
return JsonResponse(question_json_cache)
question_json = question.get_json(pk)
cache.set("{}_question_json_{}".format("longs", pk), question_json, 3600)
return JsonResponse(question_json)