diff options
author | prathamesh | 2016-08-29 15:08:04 +0530 |
---|---|---|
committer | prathamesh | 2016-08-29 15:08:04 +0530 |
commit | 95a910aee400c7706ae8f14a94eb3c9ea9289c91 (patch) | |
tree | 7ee8fc707bd1e48fd6ce67d0fdea2a1e8f0af650 /yaksh/models.py | |
parent | e1e299b671a19b65705fb256d282e1e802a4c051 (diff) | |
download | online_test-95a910aee400c7706ae8f14a94eb3c9ea9289c91.tar.gz online_test-95a910aee400c7706ae8f14a94eb3c9ea9289c91.tar.bz2 online_test-95a910aee400c7706ae8f14a94eb3c9ea9289c91.zip |
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.
Diffstat (limited to 'yaksh/models.py')
-rw-r--r-- | yaksh/models.py | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index 73d4b27..6f11c09 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -784,21 +784,28 @@ class AnswerPaper(models.Model): Adds the completed question to the list of answered questions and returns the next question. """ + next_question = self.next_question(question_id) self.questions_answered.add(question_id) self.questions_unanswered.remove(question_id) + if next_question.id == int(question_id): + return None + return next_question - return self.current_question() - - def skip(self, question_id): + def next_question(self, question_id): """ Skips the current question and returns the next sequentially available question. """ - questions = self.questions_unanswered.all() - question_cycle = cycle(questions) - for question in question_cycle: - if question.id==int(question_id): - return question_cycle.next() + unanswered_questions = self.questions_unanswered.all() + questions = list(unanswered_questions.values_list('id', flat=True)) + if len(questions) == 0: + return None + try: + index = questions.index(int(question_id)) + next_id = questions[index+1] + except (ValueError, IndexError): + next_id = questions[0] + return unanswered_questions.get(id=next_id) def time_left(self): """Return the time remaining for the user in seconds.""" |