diff options
author | Prabhu Ramachandran | 2017-03-08 15:59:18 +0530 |
---|---|---|
committer | GitHub | 2017-03-08 15:59:18 +0530 |
commit | 0a8000387b3edd463cc58b7fb85f76639f10b150 (patch) | |
tree | 3aba6618219a203a3bda5d4c85ef0ad1c229ab1d /yaksh/models.py | |
parent | aede1c3736077387d63eacd20c2c39d8875e605d (diff) | |
parent | f57cfacf41f8a1d72a56ea8c875f906e7db2a15e (diff) | |
download | online_test-0a8000387b3edd463cc58b7fb85f76639f10b150.tar.gz online_test-0a8000387b3edd463cc58b7fb85f76639f10b150.tar.bz2 online_test-0a8000387b3edd463cc58b7fb85f76639f10b150.zip |
Merge pull request #229 from ankitjavalkar/reattempt-mcq
Allow to reattempt all types of questions
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 2d84622..398f508 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -982,15 +982,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 @@ -999,16 +1001,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.""" |