From 95a910aee400c7706ae8f14a94eb3c9ea9289c91 Mon Sep 17 00:00:00 2001 From: prathamesh Date: Mon, 29 Aug 2016 15:08:04 +0530 Subject: Views sometimes use cent percent CPU, fixed After correct submission(POST) of code question, same question is shown for 2 seconds with a message "Correct Output". After 2 seconds, the same correctly answered question is resubmitted(GET) to the server.Since the question is already answered, it skips the question using the skip method of answerpaper. In skip method we have used cycle itertool, which loops in a cyclic manner, never ending. So it is terminated when we get a question match in an unanswered questions list with the submitted question. But the question is already answered so we never get a match and loop runs infinitely. So used list instead of cycle. Also, after correct answer, the user is to always get first question in the answered list of question instead of next question after the answered one. So changed the completed_question method of answerpaper. --- yaksh/views.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'yaksh/views.py') diff --git a/yaksh/views.py b/yaksh/views.py index e1ec44e..2ee964f 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -460,10 +460,12 @@ def skip(request, q_id, next_q=None, attempt_num=None, questionpaper_id=None): correct=False, skipped=True) new_answer.save() paper.answers.add(new_answer) - if next_q is None: - next_q = paper.skip(q_id) if paper.skip(q_id) else question - else: + if next_q is not None: next_q = get_object_or_404(Question, pk=next_q) + if next_q not in paper.questions_unanswered.all(): + return show_question(request, question, paper) + else: + next_q = paper.next_question(q_id) return show_question(request, next_q, paper) @@ -475,7 +477,7 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None): question_paper=questionpaper_id) question = get_object_or_404(Question, pk=q_id) if question in paper.questions_answered.all(): - next_q = paper.skip(q_id) + next_q = paper.next_question(q_id) return show_question(request, next_q, paper) if request.method == 'POST': -- cgit