From 9f3402800e1fe209ca1f3b57cca17d04ded18214 Mon Sep 17 00:00:00 2001
From: Tom Walker
Date: Mon, 21 Jul 2014 15:46:48 +0100
Subject: [PATCH] added two new fields to the quiz model which are used to
customise the success message - one is displayed if you pass the exam, the
other is shown if you fail
---
quiz/models.py | 13 +++++++++++++
quiz/templates/result.html | 10 +++-------
quiz/tests.py | 9 +++++++--
3 files changed, 23 insertions(+), 9 deletions(-)
diff --git a/quiz/models.py b/quiz/models.py
index 5524bb5..79f4b5f 100644
--- a/quiz/models.py
+++ b/quiz/models.py
@@ -83,6 +83,12 @@ class Quiz(models.Model):
validators=[
MaxValueValidator(100)])
+ success_text = models.TextField(blank=True,
+ help_text="Displayed if user passes.")
+
+ fail_text = models.TextField(blank=True,
+ help_text="Displayed if user fails.")
+
def save(self, force_insert=False, force_update=False, *args, **kwargs):
self.url = re.sub('\s+', '-', self.url).lower()
@@ -393,6 +399,13 @@ class Sitting(models.Model):
else:
return False
+ @property
+ def result_message(self):
+ if self.check_if_passed:
+ return self.quiz.success_text
+ else:
+ return self.quiz.fail_text
+
class Question(models.Model):
"""
diff --git a/quiz/templates/result.html b/quiz/templates/result.html
index 6d3170f..efb8cb8 100644
--- a/quiz/templates/result.html
+++ b/quiz/templates/result.html
@@ -38,13 +38,9 @@
{% if quiz.pass_mark %}
-
- {% if sitting.check_if_passed %}
- You have passed this exam.
- {% else %}
- You have not passed this exam.
- {% endif %}
-
+
+ {{ sitting.result_message }}
+
{% endif %}
diff --git a/quiz/tests.py b/quiz/tests.py
index a6de7af..a9a0d3f 100644
--- a/quiz/tests.py
+++ b/quiz/tests.py
@@ -173,7 +173,9 @@ class TestSitting(TestCase):
title='test quiz 1',
description='d1',
url='tq1',
- pass_mark=50)
+ pass_mark=50,
+ success_text="Well done",
+ fail_text="Bad luck")
self.question1 = MCQuestion.objects.create(id=1,
content='squawk')
@@ -206,6 +208,7 @@ class TestSitting(TestCase):
def test_scoring(self):
self.assertEqual(self.sitting.get_current_score, 0)
self.assertEqual(self.sitting.check_if_passed, False)
+ self.assertEqual(self.sitting.result_message, 'Bad luck')
self.sitting.add_to_score(1)
self.assertEqual(self.sitting.get_current_score, 1)
@@ -220,6 +223,7 @@ class TestSitting(TestCase):
self.assertEqual(self.sitting.get_percent_correct, 100)
self.assertEqual(self.sitting.check_if_passed, True)
+ self.assertEqual(self.sitting.result_message, 'Well done')
def test_incorrect_and_complete(self):
self.assertEqual(self.sitting.get_incorrect_questions(), [])
@@ -465,7 +469,8 @@ class TestQuestionViewsUser(TestCase):
description='d1',
url='tq1',
category=self.c1,
- pass_mark=50)
+ pass_mark=50,
+ success_text="You have passed")
self.quiz2 = Quiz.objects.create(id=2,
title='test quiz 2',
--
2.39.5