From d269458a198ba03035ade1fe83cc05eb5a2947b2 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Thu, 21 May 2020 15:53:26 +0530 Subject: Check if attempts are allowed and spare time is available before answer is checked --- yaksh/views.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'yaksh') diff --git a/yaksh/views.py b/yaksh/views.py index e4a9038..44c3940 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -738,10 +738,17 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None, question_paper=questionpaper_id, course_id=course_id ) + questionpaper = QuestionPaper.objects.get(id=questionpaper_id) current_question = get_object_or_404(Question, pk=q_id) if request.method == 'POST': # Add the answer submitted, regardless of it being correct or not. + if paper.time_left() <= 0 or questionpaper.can_attempt_now(user, course_id)[0]: + reason = 'Your time is up!' + return complete( + request, reason, paper.attempt_number, paper.question_paper.id, + course_id, module_id=module_id + ) if current_question.type == 'mcq': user_answer = request.POST.get('answer') elif current_question.type == 'integer': -- cgit From bff6dc7a6234535df8143cd35fa455333a4eefab Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Thu, 21 May 2020 17:33:23 +0530 Subject: Fix check condition and alter tests --- yaksh/test_views.py | 4 ++-- yaksh/views.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'yaksh') diff --git a/yaksh/test_views.py b/yaksh/test_views.py index 24750e3..a7ccac2 100644 --- a/yaksh/test_views.py +++ b/yaksh/test_views.py @@ -5496,8 +5496,8 @@ class TestQuestionPaper(TestCase): self.answerpaper = AnswerPaper.objects.create( user=self.user, question_paper=self.question_paper, attempt_number=1, - start_time=datetime(2014, 10, 9, 10, 8, 15, 0, tzone), - end_time=datetime(2014, 10, 9, 10, 15, 15, 0, tzone), + start_time=timezone.now() - timezone.timedelta(minutes = 10), + end_time=timezone.now() - timezone.timedelta(minutes = 1), user_ip="127.0.0.1", status="inprogress", passed=False, percent=0, marks_obtained=0, course=self.course ) diff --git a/yaksh/views.py b/yaksh/views.py index 44c3940..d8502a3 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -743,7 +743,7 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None, if request.method == 'POST': # Add the answer submitted, regardless of it being correct or not. - if paper.time_left() <= 0 or questionpaper.can_attempt_now(user, course_id)[0]: + if paper.time_left() <= 0 or not questionpaper.can_attempt_now(user, course_id)[0]: reason = 'Your time is up!' return complete( request, reason, paper.attempt_number, paper.question_paper.id, -- cgit From b3b450f7c575f9cf8ed9a8b12e495f4be0adc143 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Tue, 26 May 2020 12:33:30 +0530 Subject: Change condition and function name --- yaksh/views.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'yaksh') diff --git a/yaksh/views.py b/yaksh/views.py index d8502a3..d034b9d 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -738,12 +738,11 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None, question_paper=questionpaper_id, course_id=course_id ) - questionpaper = QuestionPaper.objects.get(id=questionpaper_id) current_question = get_object_or_404(Question, pk=q_id) if request.method == 'POST': # Add the answer submitted, regardless of it being correct or not. - if paper.time_left() <= 0 or not questionpaper.can_attempt_now(user, course_id)[0]: + if (paper.time_left() <= -10 or paper.status == "completed"): reason = 'Your time is up!' return complete( request, reason, paper.attempt_number, paper.question_paper.id, -- cgit