summaryrefslogtreecommitdiff
path: root/yaksh/models.py
diff options
context:
space:
mode:
authorprathamesh2016-08-31 01:37:20 +0530
committerprathamesh2016-08-31 01:37:20 +0530
commit24593514378e86cd2f0ef62e11e8a4c9dee0f5ad (patch)
tree686d263a31445a19d6addd4fca13e9bb1041755d /yaksh/models.py
parent11dec9deba7120f85d3d2b47cfd31fca8587bbbc (diff)
parentaefc8eed3b0c18520059b4005978f1db9cf5591b (diff)
downloadonline_test-24593514378e86cd2f0ef62e11e8a4c9dee0f5ad.tar.gz
online_test-24593514378e86cd2f0ef62e11e8a4c9dee0f5ad.tar.bz2
online_test-24593514378e86cd2f0ef62e11e8a4c9dee0f5ad.zip
Merge branch 'master' of https://github.com/FOSSEE/online_test into view_answerpaper
Resolved Conflicts: yaksh/views.py
Diffstat (limited to 'yaksh/models.py')
-rw-r--r--yaksh/models.py27
1 files changed, 18 insertions, 9 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index eb73499..81926e6 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -573,7 +573,9 @@ class QuestionPaper(models.Model):
if self.quiz.has_prerequisite():
prerequisite = self._get_prequisite_paper()
return prerequisite._is_questionpaper_passed(user)
-
+
+ def __unicode__(self):
+ return "Question Paper for " + self.quiz.description
###############################################################################
class QuestionSet(models.Model):
@@ -787,21 +789,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."""