summaryrefslogtreecommitdiff
path: root/testapp/exam/views.py
diff options
context:
space:
mode:
authorprathamesh2015-02-24 14:13:38 +0530
committerprathamesh2015-02-24 14:13:38 +0530
commitda7014b32635f47d0fd66931ce5961e54f82ae94 (patch)
tree762157219f97e1669230aa5df96f9776f6920df6 /testapp/exam/views.py
parentff5fc201bf7f44a6dc9d6d93fee7bc0ce47d1be2 (diff)
downloadonline_test-da7014b32635f47d0fd66931ce5961e54f82ae94.tar.gz
online_test-da7014b32635f47d0fd66931ce5961e54f82ae94.tar.bz2
online_test-da7014b32635f47d0fd66931ce5961e54f82ae94.zip
Answer is now saved from the question navigator as well
Diffstat (limited to 'testapp/exam/views.py')
-rw-r--r--testapp/exam/views.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/testapp/exam/views.py b/testapp/exam/views.py
index 576405f..ba48b60 100644
--- a/testapp/exam/views.py
+++ b/testapp/exam/views.py
@@ -754,6 +754,29 @@ def question(request, q_id, attempt_no, questionpaper_id, success_msg=None):
def show_question(request, q_id, attempt_no, questionpaper_id, success_msg=None):
"""Show a question if possible."""
+ user = request.user
+ q_paper = QuestionPaper.objects.get(id=questionpaper_id)
+ paper = AnswerPaper.objects.get(user=request.user, attempt_number=attempt_no,
+ question_paper=q_paper)
+ if not user.is_authenticated() or paper.end_time < datetime.datetime.now():
+ return my_redirect('/exam/login/')
+ old_qid = request.POST.get('question_id')
+ if old_qid is not None:
+
+ quest = Question.objects.get(pk=old_qid)
+ user_code = request.POST.get('answer')
+ if quest.type == 'code':
+ user_answer = user_code # not taking snippet here.
+ old_skipped = paper.answers.filter(question=quest, skipped=True)
+ if old_skipped:
+ skipped_answer = old_skipped[0]
+ skipped_answer.answer=user_answer
+ skipped_answer.save()
+ else:
+ skipped_answer = Answer(question=quest, answer=user_answer,
+ correct=False, skipped=True)
+ skipped_answer.save()
+ paper.answers.add(skipped_answer)
if len(q_id) == 0:
msg = 'Congratulations! You have successfully completed the quiz.'
return complete(request, msg, attempt_no, questionpaper_id)