.
This commit is contained in:
+7
-7
@@ -374,14 +374,14 @@ class ExamViews(View, LoginRequiredMixin):
|
|||||||
if not exam.active:
|
if not exam.active:
|
||||||
raise Http404("No available exam")
|
raise Http404("No available exam")
|
||||||
|
|
||||||
exam_json_cache = cache.get("{}_exam_json_{}_{}".format(self.app_name, pk, sk))
|
question_json_cache = cache.get("{}_question_json_{}".format(self.app_name, sk))
|
||||||
|
|
||||||
if exam_json_cache is not None and not exam.recreate_json:
|
if question_json_cache is not None and not exam.recreate_json:
|
||||||
exam_json_cache["cached"] = True
|
question_json_cache["cached"] = True
|
||||||
return JsonResponse(exam_json_cache)
|
return JsonResponse(question_json_cache)
|
||||||
|
|
||||||
exam_json = exam.get_exam_question_json(sk)
|
question_json = exam.get_exam_question_json(sk)
|
||||||
|
|
||||||
cache.set("{}_exam_json_{}_{}".format(self.app_name, pk, sk), exam_json, 3600)
|
cache.set("{}_question_json_{}".format(self.app_name, sk), question_json, 3600)
|
||||||
|
|
||||||
return JsonResponse(exam_json)
|
return JsonResponse(question_json)
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 3.1.3 on 2021-02-28 16:28
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('longs', '0029_auto_20210225_1819'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='long',
|
||||||
|
name='recreate_json',
|
||||||
|
field=models.BooleanField(default=False, help_text='If the json cache needs updating'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -114,6 +114,10 @@ class Long(models.Model):
|
|||||||
help_text="If a question should be freely available to browse", default=True
|
help_text="If a question should be freely available to browse", default=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
recreate_json = models.BooleanField(
|
||||||
|
help_text="If the json cache needs updating", default=False
|
||||||
|
)
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse("longs:long_detail", kwargs={"pk": self.pk})
|
return reverse("longs:long_detail", kwargs={"pk": self.pk})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user