From a1f73afec599e34cfb63731b1506ff5978239237 Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 28 Dec 2020 10:18:34 +0000 Subject: [PATCH] add time limit to exams --- anatomy/migrations/0014_exam_time_limit.py | 18 ++++++++++++++++++ anatomy/models.py | 16 ++++++++++------ anatomy/views.py | 3 +++ 3 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 anatomy/migrations/0014_exam_time_limit.py diff --git a/anatomy/migrations/0014_exam_time_limit.py b/anatomy/migrations/0014_exam_time_limit.py new file mode 100644 index 00000000..fab14570 --- /dev/null +++ b/anatomy/migrations/0014_exam_time_limit.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.3 on 2020-12-28 10:17 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('anatomy', '0013_auto_20201227_1200'), + ] + + operations = [ + migrations.AddField( + model_name='exam', + name='time_limit', + field=models.IntegerField(default=False, help_text='Exam time limit (in seconds)'), + ), + ] diff --git a/anatomy/models.py b/anatomy/models.py index 663f6d73..5c19713f 100644 --- a/anatomy/models.py +++ b/anatomy/models.py @@ -181,7 +181,9 @@ class AnatomyQuestion(models.Model): if i.status != i.MarkOptions.UNMARKED ] ) - correct_answers = set([i.answer.get_compare_string() for i in self.answers.all()]) + correct_answers = set( + [i.answer.get_compare_string() for i in self.answers.all()] + ) half_mark_answers = set( [i.answer.get_compare_string() for i in self.half_mark_answers.all()] ) @@ -266,6 +268,10 @@ class Exam(models.Model): help_text="If the json cache needs updating", default=False ) + time_limit = models.IntegerField( + help_text="Exam time limit (in seconds)", default=False + ) + def __str__(self): return self.name @@ -366,11 +372,9 @@ class CidUserAnswer(models.Model): is not None ): mark = 1 - elif ( - q.answers.filter( - answer__iexact=ans, status=Answer.MarkOptions.INCORRECT - ).first() - ): + elif q.answers.filter( + answer__iexact=ans, status=Answer.MarkOptions.INCORRECT + ).first(): mark = 0 else: mark = "unmarked" diff --git a/anatomy/views.py b/anatomy/views.py index cd6fb085..52118477 100644 --- a/anatomy/views.py +++ b/anatomy/views.py @@ -585,6 +585,9 @@ def exam_json(request, pk): "questions": exam_questions, } + if exam.time_limit: + exam_json["exam_time"] = exam.time_limit + exam.recreate_json = False exam.save()