diff options
author | ankitjavalkar | 2018-03-20 15:26:22 +0530 |
---|---|---|
committer | ankitjavalkar | 2018-04-17 15:28:35 +0530 |
commit | e97249a733a8d915bc50228867ae6ad633d77ae6 (patch) | |
tree | c4e738345344379e6462fafa46de8e2c17f73d04 | |
parent | a7b0c232991208625564f76a56d078e9391c5cb2 (diff) | |
download | online_test-e97249a733a8d915bc50228867ae6ad633d77ae6.tar.gz online_test-e97249a733a8d915bc50228867ae6ad633d77ae6.tar.bz2 online_test-e97249a733a8d915bc50228867ae6ad633d77ae6.zip |
Multiple changes in models
- Add error message to can_attempt_now Questionpaper model method
- Add default value to Quiz time_between_attempt field
-rw-r--r-- | yaksh/models.py | 15 | ||||
-rw-r--r-- | yaksh/views.py | 7 |
2 files changed, 15 insertions, 7 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, diff --git a/yaksh/views.py b/yaksh/views.py index 1cb77fc..dd62ec5 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -534,9 +534,10 @@ def start(request, questionpaper_id=None, attempt_num=None, course_id=None, previous_question=last_attempt.current_question() ) # allowed to start - if not quest_paper.can_attempt_now(user, course_id): - msg = "You cannot attempt {0} quiz more than {1} time(s)".format( - quest_paper.quiz.description, quest_paper.quiz.attempts_allowed) + if not quest_paper.can_attempt_now(user, course_id)[0]: + # msg = "You cannot attempt {0} quiz more than {1} time(s)".format( + # quest_paper.quiz.description, quest_paper.quiz.attempts_allowed) + msg = quest_paper.can_attempt_now(user, course_id)[1] if is_moderator(user): return prof_manage(request, msg=msg) return view_module(request, module_id=module_id, course_id=course_id, |