add time limit to exams

This commit is contained in:
Ross
2020-12-28 10:18:34 +00:00
parent 0b09d1d4cc
commit a1f73afec5
3 changed files with 31 additions and 6 deletions
@@ -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)'),
),
]
+10 -6
View File
@@ -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"
+3
View File
@@ -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()