From 60503c9bd1ea49177f0adfc39ff129bfba86c9de Mon Sep 17 00:00:00 2001 From: prathamesh Date: Fri, 27 Nov 2020 04:18:27 +0530 Subject: Fix answer paper view. - Slight optimisation in retrieving and rendering the data - avoids the arrange type question's custom filter error - Marks obtained appears properly on all the interface(user view answerpaper, monitor and grade user) - if not attempted then shows the question and says "Did not attempt" --- yaksh/models.py | 55 +++++++++++------------------ yaksh/templates/yaksh/grade_user.html | 14 ++++---- yaksh/templates/yaksh/user_data.html | 17 +++++---- yaksh/templates/yaksh/view_answerpaper.html | 14 ++++---- 4 files changed, 43 insertions(+), 57 deletions(-) (limited to 'yaksh') diff --git a/yaksh/models.py b/yaksh/models.py index 50e9363..2978f43 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -2321,14 +2321,20 @@ class AnswerPaper(models.Model): secs = dt.seconds + dt.days*24*3600 return secs + def _get_marks_for_question(self, question): + marks = 0.0 + answers = question.answer_set.filter(answerpaper=self) + if answers.exists(): + marks = [answer.marks for answer in answers] + max_marks = max(marks) + marks = max_marks + return marks + def _update_marks_obtained(self): """Updates the total marks earned by student for this paper.""" - marks = 0 + marks = 0.0 for question in self.questions.all(): - marks_list = [a.marks - for a in self.answers.filter(question=question)] - max_marks = max(marks_list) if marks_list else 0.0 - marks += max_marks + marks += self._get_marks_for_question(question) self.marks_obtained = marks def _update_percent(self): @@ -2376,38 +2382,19 @@ class AnswerPaper(models.Model): corresponding answers. """ q_a = {} - for answer in self.answers.all(): - question = answer.question - if question in q_a: - q_a[question].append({ - 'answer': answer, - 'error_list': [e for e in json.loads(answer.error)] - }) - else: - q_a[question] = [{ + for question in self.questions.all(): + answers = question.answer_set.filter(answerpaper=self) + if not answers.exists(): + q_a[question] = [None, 0.0] + continue + ans_errs = [] + for answer in answers: + ans_errs.append({ 'answer': answer, 'error_list': [e for e in json.loads(answer.error)] - }] - - q_a.update( - { q: [] for q in self.questions_unanswered.all() } - ) - - for question, answers in q_a.items(): - answers = q_a[question] - if answers: - q_a[question].append({ - 'marks': max([ - answer['answer'].marks - for answer in answers - if question == answer['answer'].question - ]), }) - else: - q_a[question].append({ - 'marks': 0.0, - }) - + q_a[question] = ans_errs + q_a[question].append(self._get_marks_for_question(question)) return q_a def get_latest_answer(self, question_id): diff --git a/yaksh/templates/yaksh/grade_user.html b/yaksh/templates/yaksh/grade_user.html index 341fd7c..64b9cb5 100644 --- a/yaksh/templates/yaksh/grade_user.html +++ b/yaksh/templates/yaksh/grade_user.html @@ -319,7 +319,6 @@ function searchNames() { {% for question, answers in paper.get_question_answers.items %} - {% with answers|last as answer %} @@ -327,14 +326,13 @@ function searchNames() { {{ question.type }} - {{ answer.marks }} + {{ answers|last }}  Regrade - {% endwith %} {% endfor %} @@ -437,7 +435,10 @@ function searchNames() { {% endif %} {% else %} - {% for ans in answers %} + {% if answers|first is None %} +

Did not attempt

+ {% else %} + {% for ans in answers|slice:":-1" %} Attempt Number: {{forloop.counter}} @@ -559,6 +560,7 @@ function searchNames() {
{% endfor %} + {% endif %} {% endif %} @@ -566,9 +568,7 @@ function searchNames() {
- {% with answers|last as answer %} -

- {% endwith %} +


diff --git a/yaksh/templates/yaksh/user_data.html b/yaksh/templates/yaksh/user_data.html index a79071d..0506df0 100644 --- a/yaksh/templates/yaksh/user_data.html +++ b/yaksh/templates/yaksh/user_data.html @@ -78,11 +78,7 @@ {{question.summary}} {{question.type}} - - {% for answer in answers %} - {{answer.marks}} - {% endfor %} - + {{ answers|last }} {% endfor %} @@ -181,7 +177,11 @@ {% endif %} {% else %} - {% for ans in answers %} + + {% if answers|first is None %} +

Did not attempt

+ {% else %} + {% for ans in answers|slice:":-1" %} Attempt Number: {{forloop.counter}} @@ -303,6 +303,7 @@
{% endfor %} + {% endif %} {% endif %} @@ -310,9 +311,7 @@
- {% with answers|last as answer %} -

- {% endwith %} +


diff --git a/yaksh/templates/yaksh/view_answerpaper.html b/yaksh/templates/yaksh/view_answerpaper.html index 905a111..775525e 100644 --- a/yaksh/templates/yaksh/view_answerpaper.html +++ b/yaksh/templates/yaksh/view_answerpaper.html @@ -80,7 +80,6 @@ {% for question, answers in paper.get_question_answers.items %} - {% with answers|last as answer %} @@ -88,9 +87,8 @@ {{ question.type }} - {{ answer.answer.marks }} + {{ answers|last }}{{ answer.answer.marks }} - {% endwith %} {% endfor %} @@ -200,7 +198,10 @@ {% endif %} {% else %} - {% for ans in answers %} + {% if answers|first is None %} +

Did not attempt

+ {% else %} + {% for ans in answers|slice:":-1" %} Attempt Number: {{forloop.counter}} @@ -324,6 +325,7 @@
{% endfor %} + {% endif %} {% endif %} @@ -331,9 +333,7 @@
- {% with answers|last as answer %} -

- {% endwith %} +


-- cgit