diff options
author | prathamesh | 2015-03-31 17:41:05 +0530 |
---|---|---|
committer | prathamesh | 2015-03-31 17:41:05 +0530 |
commit | 9b7df35eca1557982155fdcc7993b4a7ba77235b (patch) | |
tree | 549e75dd855937cfe0c6fb769bd78e0bf74c7e73 /testapp/exam/views.py | |
parent | da7014b32635f47d0fd66931ce5961e54f82ae94 (diff) | |
download | online_test-9b7df35eca1557982155fdcc7993b4a7ba77235b.tar.gz online_test-9b7df35eca1557982155fdcc7993b4a7ba77235b.tar.bz2 online_test-9b7df35eca1557982155fdcc7993b4a7ba77235b.zip |
Created a function to save skipped questions.
If the question is skipped for the first time then a new object of the
answer is created, else the old skipped answer object is modified.
Diffstat (limited to 'testapp/exam/views.py')
-rw-r--r-- | testapp/exam/views.py | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/testapp/exam/views.py b/testapp/exam/views.py index ba48b60..7103006 100644 --- a/testapp/exam/views.py +++ b/testapp/exam/views.py @@ -762,27 +762,31 @@ def show_question(request, q_id, attempt_no, questionpaper_id, success_msg=None) 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) + _save_skipped_answer(old_skipped, user_code, paper) if len(q_id) == 0: msg = 'Congratulations! You have successfully completed the quiz.' return complete(request, msg, attempt_no, questionpaper_id) else: return question(request, q_id, attempt_no, questionpaper_id, success_msg) +def _save_skipped_answer(old_skipped, user_answer, paper): + """ + Saves the answer on skip. Only the code questions are saved. + Snippet is not saved with the answer. + """ + 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) def check(request, q_id, attempt_no=None, questionpaper_id=None): """Checks the answers of the user for particular question""" @@ -801,17 +805,8 @@ def check(request, q_id, attempt_no=None, questionpaper_id=None): success = True if skip is not None: if question.type == 'code': - user_answer = user_code # not taking snippet here. old_skipped = paper.answers.filter(question=question, skipped=True) - if old_skipped: - skipped_answer = old_skipped[0] - skipped_answer.answer=user_answer - skipped_answer.save() - else: - skipped_answer = Answer(question=question, answer=user_answer, - correct=False, skipped=True) - skipped_answer.save() - paper.answers.add(skipped_answer) + _save_skipped_answer(old_skipped, user_code, paper) next_q = paper.skip() return show_question(request, next_q, attempt_no, questionpaper_id) |