diff options
author | Prabhu Ramachandran | 2016-08-30 16:29:03 +0530 |
---|---|---|
committer | GitHub | 2016-08-30 16:29:03 +0530 |
commit | aefc8eed3b0c18520059b4005978f1db9cf5591b (patch) | |
tree | 6be0dc028784f4db97115f3b4b2bd0d02c2a0262 /yaksh/models.py | |
parent | fb1877472b80b45d51e926966d6d21ca80b9ae9f (diff) | |
parent | 45cfca69a8af52fb838de48706ed5e4ddc1b1042 (diff) | |
download | online_test-aefc8eed3b0c18520059b4005978f1db9cf5591b.tar.gz online_test-aefc8eed3b0c18520059b4005978f1db9cf5591b.tar.bz2 online_test-aefc8eed3b0c18520059b4005978f1db9cf5591b.zip |
Merge pull request #128 from prathamesh920/bug_fixes
Bug fixes
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 898662c..acb46f2 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -786,21 +786,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.""" |