diff options
author | ankitjavalkar | 2015-05-21 18:41:59 +0530 |
---|---|---|
committer | ankitjavalkar | 2015-06-01 16:33:56 +0530 |
commit | f49b5644b5c4cc2db40d810b3e2b2e4191033c06 (patch) | |
tree | 2e160e2697f7538e8bdf7acf1bd4cd99fa4b9718 /testapp/exam/models.py | |
parent | 5ea5324aba75b3d76c2c1d275851d3da06d78d63 (diff) | |
download | online_test-f49b5644b5c4cc2db40d810b3e2b2e4191033c06.tar.gz online_test-f49b5644b5c4cc2db40d810b3e2b2e4191033c06.tar.bz2 online_test-f49b5644b5c4cc2db40d810b3e2b2e4191033c06.zip |
Add Multiple Features based on feedback
- Remove Attempt later button on last question
- Improve mechanism for cycling through
- Add attempt summary on Quit or Completion
- Fix error paginator not displaying on error
Diffstat (limited to 'testapp/exam/models.py')
-rw-r--r-- | testapp/exam/models.py | 53 |
1 files changed, 37 insertions, 16 deletions
diff --git a/testapp/exam/models.py b/testapp/exam/models.py index c5043dc..deb9b2a 100644 --- a/testapp/exam/models.py +++ b/testapp/exam/models.py @@ -245,6 +245,8 @@ class QuestionPaper(models.Model): if self.shuffle_questions: shuffle(question_ids) ans_paper.questions = "|".join(question_ids) + if not ans_paper.questions_unanswered: + ans_paper.questions_unanswered = ans_paper.questions ans_paper.save() return ans_paper @@ -298,6 +300,9 @@ class AnswerPaper(models.Model): # The questions successfully answered (a list of ids separated by '|') questions_answered = models.CharField(max_length=128) + # The unanswered questions (a list of ids separated by '|') + questions_unanswered = models.CharField(max_length=128) + # All the submitted answers. answers = models.ManyToManyField(Answer) @@ -317,9 +322,14 @@ class AnswerPaper(models.Model): status = models.CharField(max_length=20, choices=test_status,\ default='inprogress') + # def initialise_questions_unanswered(self): + # if not self.questions_unanswered: + # self.questions_unanswered = self.questions + # self.save() + def current_question(self): """Returns the current active question to display.""" - qs = self.questions.split('|') + qs = self.questions_unanswered.split('|') if len(qs) > 0: return qs[0] else: @@ -327,7 +337,7 @@ class AnswerPaper(models.Model): def questions_left(self): """Returns the number of questions left.""" - qs = self.questions + qs = self.questions_unanswered if len(qs) == 0: return 0 else: @@ -343,29 +353,40 @@ class AnswerPaper(models.Model): self.questions_answered = '|'.join([qa, str(question_id)]) else: self.questions_answered = str(question_id) - qs = self.questions.split('|') - qs.remove(unicode(question_id)) - self.questions = '|'.join(qs) - self.save() + qs = self.questions_unanswered.split('|') + try: + q_index = qs.index(unicode(question_id)) + qs.remove(unicode(question_id)) + self.questions_unanswered = '|'.join(qs) if qs else "" + self.save() + except ValueError: + q_index = qs[0] if len(qs) == 0: return '' else: - return qs[0] + if q_index in range(0, len(qs)-1): + return qs[q_index] + else: + return qs[0] - def skip(self): + def skip(self, question_id): """ - Skips the current question and returns the next available question. + Skips the current question and returns the next sequentially + available question. """ - qs = self.questions.split('|') + qs = self.questions_unanswered.split('|') if len(qs) == 0: return '' else: - # Put head at the end. - head = qs.pop(0) - qs.append(head) - self.questions = '|'.join(qs) - self.save() - return qs[0] + try: + q_index = qs.index(unicode(question_id)) + except ValueError: + q_index = qs[0] + if q_index in range(0, len(qs)-1): + next_q = qs[q_index + 1] + else: + next_q = qs[0] + return next_q def time_left(self): """Return the time remaining for the user in seconds.""" |