diff options
author | maheshgudi | 2017-03-09 01:27:39 +0530 |
---|---|---|
committer | maheshgudi | 2017-03-09 01:27:39 +0530 |
commit | 8e2bf890d38d4ab2ac73180ff4982302d9355b75 (patch) | |
tree | f89d88101c867927628961bf0a856d3c68824999 /yaksh/models.py | |
parent | 1c5e1dfef3fb4af8bc070fe190cec552ef3732b0 (diff) | |
parent | 69951e247ea02196ec6e65324f77898d9ea389b3 (diff) | |
download | online_test-8e2bf890d38d4ab2ac73180ff4982302d9355b75.tar.gz online_test-8e2bf890d38d4ab2ac73180ff4982302d9355b75.tar.bz2 online_test-8e2bf890d38d4ab2ac73180ff4982302d9355b75.zip |
rebase changes
Diffstat (limited to 'yaksh/models.py')
-rw-r--r-- | yaksh/models.py | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index fdf10bd..a323994 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -992,15 +992,17 @@ class AnswerPaper(models.Model): """Returns the number of questions left.""" return self.questions_unanswered.count() - def completed_question(self, question_id): + def add_completed_question(self, question_id): """ 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) + if question_id not in self.questions_answered.all(): + self.questions_answered.add(question_id) self.questions_unanswered.remove(question_id) - if next_question.id == int(question_id): + + next_question = self.next_question(question_id) + if next_question and next_question.id == int(question_id): return None return next_question @@ -1009,16 +1011,19 @@ class AnswerPaper(models.Model): Skips the current question and returns the next sequentially available question. """ + all_questions = self.questions.all() unanswered_questions = self.questions_unanswered.all() - questions = list(unanswered_questions.values_list('id', flat=True)) + questions = list(all_questions.values_list('id', flat=True)) if len(questions) == 0: return None + if unanswered_questions.count() == 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) + return all_questions.get(id=next_id) def time_left(self): """Return the time remaining for the user in seconds.""" |