From f49b5644b5c4cc2db40d810b3e2b2e4191033c06 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Thu, 21 May 2015 18:41:59 +0530 Subject: 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 --- testapp/exam/models.py | 53 ++++++++++++++++------- testapp/exam/templates/exam/complete.html | 27 ++++++++++-- testapp/exam/templates/exam/question.html | 5 ++- testapp/exam/templates/exam/quit.html | 29 +++++++++++-- testapp/exam/views.py | 71 +++++++++++++++++++++---------- testapp/exam/xmlrpc_clients.py | 1 + 6 files changed, 138 insertions(+), 48 deletions(-) (limited to 'testapp/exam') 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.""" diff --git a/testapp/exam/templates/exam/complete.html b/testapp/exam/templates/exam/complete.html index 1d5df3c..08abe76 100644 --- a/testapp/exam/templates/exam/complete.html +++ b/testapp/exam/templates/exam/complete.html @@ -5,8 +5,29 @@ {% block pagetitle %}Online Test{% endblock %} {% block content %} {% csrf_token %} -

Good bye!

-

{{message}}

-

You may now close the browser.


+ {% if submitted or unattempted %} +
+ + + + +
Submitted Questions + {% if submitted %} + {{ submitted|join:", " }} + {% else %} +

No Questions have been Submitted

+ {% endif %} +
Unattempted Questions + {% if unattempted %} + {{ unattempted|join:", " }} + {% else %} +

All Questions have been Submitted

+ {% endif %} +
+ {% endif %} +

Good bye!

+

{{message}}

+

You may now close the browser.


Login Again
{% endblock content %} diff --git a/testapp/exam/templates/exam/question.html b/testapp/exam/templates/exam/question.html index 5cc9db0..b7a7053 100644 --- a/testapp/exam/templates/exam/question.html +++ b/testapp/exam/templates/exam/question.html @@ -104,7 +104,6 @@ function call_skip(url) -