summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorankitjavalkar2020-05-21 15:53:26 +0530
committerankitjavalkar2020-05-21 16:28:05 +0530
commitd269458a198ba03035ade1fe83cc05eb5a2947b2 (patch)
tree3ad94fd528ce73262ee14dbf5e3b5298870a6d57
parentfa656e1ce81c748b354e19e6d5b8de672a58c186 (diff)
downloadonline_test-d269458a198ba03035ade1fe83cc05eb5a2947b2.tar.gz
online_test-d269458a198ba03035ade1fe83cc05eb5a2947b2.tar.bz2
online_test-d269458a198ba03035ade1fe83cc05eb5a2947b2.zip
Check if attempts are allowed and spare time is available before answer is checked
-rw-r--r--yaksh/views.py7
1 files changed, 7 insertions, 0 deletions
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':