diff options
author | Prabhu Ramachandran | 2018-05-09 19:19:29 +0530 |
---|---|---|
committer | GitHub | 2018-05-09 19:19:29 +0530 |
commit | 31764f78f091122a745a7da2d98e18160cb35eba (patch) | |
tree | 7ad6bca66e23ab3c18ea41bfa68e128c38936cbc /yaksh/models.py | |
parent | a7b0c232991208625564f76a56d078e9391c5cb2 (diff) | |
parent | f5fa97802447808744cfc591cc3855a9b57e6d32 (diff) | |
download | online_test-31764f78f091122a745a7da2d98e18160cb35eba.tar.gz online_test-31764f78f091122a745a7da2d98e18160cb35eba.tar.bz2 online_test-31764f78f091122a745a7da2d98e18160cb35eba.zip |
Merge pull request #460 from ankitjavalkar/fix-attempt-error-msg
Display appropriate error when time between attempts condition is not satisfied
Diffstat (limited to 'yaksh/models.py')
-rw-r--r-- | yaksh/models.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index d011bb0..3010a3c 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -317,7 +317,7 @@ class Quiz(models.Model): attempts_allowed = models.IntegerField(default=1, choices=attempts) time_between_attempts = models.FloatField( - "Time Between Quiz Attempts in hours" + "Time Between Quiz Attempts in hours", default=0.0 ) is_trial = models.BooleanField(default=False) @@ -1356,11 +1356,18 @@ class QuestionPaper(models.Model): ) if last_attempt: time_lag = (timezone.now() - last_attempt.start_time).total_seconds() / 3600 - return time_lag >= self.quiz.time_between_attempts + can_attempt = time_lag >= self.quiz.time_between_attempts + msg = "You cannot start the next attempt for this quiz before {0} hour(s)".format( + self.quiz.time_between_attempts + ) if not can_attempt else None + return can_attempt, msg else: - return True + return True, None else: - return False + msg = "You cannot attempt {0} quiz more than {1} time(s)".format( + self.quiz.description, self.quiz.attempts_allowed + ) + return False, msg def create_demo_quiz_ppr(self, demo_quiz, user): question_paper = QuestionPaper.objects.create(quiz=demo_quiz, |