From 30c1119d3a1a5b7aaa96b80cb431c5b34eeb23b5 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Tue, 29 Jan 2019 12:16:14 +0530 Subject: Allow student to open a quiz if status is inprogress and redirect to completion page if attempts are exceeded --- yaksh/views.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/yaksh/views.py b/yaksh/views.py index 6c7a12e..d36a5f6 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -515,23 +515,28 @@ def start(request, questionpaper_id=None, attempt_num=None, course_id=None, # if any previous attempt last_attempt = AnswerPaper.objects.get_user_last_attempt( quest_paper, user, course_id) - if last_attempt and last_attempt.is_attempt_inprogress(): - return show_question( - request, last_attempt.current_question(), last_attempt, - course_id=course_id, module_id=module_id, - previous_question=last_attempt.current_question() - ) + + if last_attempt: + if last_attempt.is_attempt_inprogress(): + return show_question( + request, last_attempt.current_question(), last_attempt, + course_id=course_id, module_id=module_id, + previous_question=last_attempt.current_question() + ) + attempt_number = last_attempt.attempt_number + 1 + else: + attempt_number = 1 + # allowed to start if not quest_paper.can_attempt_now(user, course_id)[0]: 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, - msg=msg) - if not last_attempt: - attempt_number = 1 - else: - attempt_number = last_attempt.attempt_number + 1 + return complete( + request, msg, last_attempt.attempt_number, quest_paper.id, + course_id=course_id, module_id=module_id + ) + if attempt_num is None and not quest_paper.quiz.is_exercise: context = { 'user': user, -- cgit From f1dde181a6c30d32ea4f4cf3d2d29b780c4d45a5 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Tue, 29 Jan 2019 12:17:09 +0530 Subject: Fix condition for comparison of current attempt number and maximum attempts allowed in _is_attempt_allowed --- yaksh/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yaksh/models.py b/yaksh/models.py index cce90e7..7a4d8d1 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -1600,7 +1600,7 @@ class QuestionPaper(models.Model): attempts = AnswerPaper.objects.get_total_attempt(questionpaper=self, user=user, course_id=course_id) - return attempts != self.quiz.attempts_allowed + return attempts < self.quiz.attempts_allowed or self.quiz.attempts_allowed == -1 def can_attempt_now(self, user, course_id): if self._is_attempt_allowed(user, course_id): -- cgit From c6475d2dc6c08fbaac3a0803f2b88c1aed539ff1 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Mon, 4 Mar 2019 20:21:16 +0530 Subject: Fix PEP8 issues --- yaksh/models.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/yaksh/models.py b/yaksh/models.py index 7a4d8d1..c4e5a50 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -1600,7 +1600,9 @@ class QuestionPaper(models.Model): attempts = AnswerPaper.objects.get_total_attempt(questionpaper=self, user=user, course_id=course_id) - return attempts < self.quiz.attempts_allowed or self.quiz.attempts_allowed == -1 + attempts_allowed = attempts < self.quiz.attempts_allowed + infinite_attempts = self.quiz.attempts_allowed == -1 + return attempts_allowed or infinite_attempts def can_attempt_now(self, user, course_id): if self._is_attempt_allowed(user, course_id): -- cgit