diff options
author | Prabhu Ramachandran | 2017-10-25 15:43:24 +0530 |
---|---|---|
committer | GitHub | 2017-10-25 15:43:24 +0530 |
commit | 07e5a3c831ad351d47de54db7179303be3506c10 (patch) | |
tree | 30a65b459b04ba8b5346fa32af601d12645ecf2e /yaksh/models.py | |
parent | 4e7d09eae252c6d89d2fecfe18ffce46e4421eb0 (diff) | |
parent | 90402ae9b0f2d4038099e9ea4e39f832063dd0dd (diff) | |
download | online_test-07e5a3c831ad351d47de54db7179303be3506c10.tar.gz online_test-07e5a3c831ad351d47de54db7179303be3506c10.tar.bz2 online_test-07e5a3c831ad351d47de54db7179303be3506c10.zip |
Merge pull request #367 from ankitjavalkar/fix-revisit-with-one-q
Fix revisit with one question
Diffstat (limited to 'yaksh/models.py')
-rw-r--r-- | yaksh/models.py | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/yaksh/models.py b/yaksh/models.py index f7d9906..ff326d3 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -1199,11 +1199,12 @@ class AnswerPaper(models.Model): def get_current_question(self, questions): if self.questions_order: - question_id = int(self.questions_order.split(',')[0]) - question = questions.get(id=question_id) - else: - question = questions.first() - return question + available_question_ids = questions.values_list('id', flat=True) + ordered_question_ids = [int(q) for q in self.questions_order.split(',')] + for qid in ordered_question_ids: + if qid in available_question_ids: + return questions.get(id=qid) + return questions.first() def questions_left(self): """Returns the number of questions left.""" @@ -1218,10 +1219,7 @@ class AnswerPaper(models.Model): self.questions_answered.add(question_id) self.questions_unanswered.remove(question_id) - next_question = self.next_question(question_id) - if next_question and next_question.id == int(question_id): - return None - return next_question + return self.next_question(question_id) def next_question(self, question_id): """ @@ -1229,8 +1227,9 @@ class AnswerPaper(models.Model): available question. """ if self.questions_order: - all_questions = [int(q_id) - for q_id in self.questions_order.split(',')] + all_questions = [ + int(q_id) for q_id in self.questions_order.split(',') + ] else: all_questions = list(self.questions.all().values_list( 'id', flat=True)) |