diff options
-rw-r--r-- | yaksh/models.py | 55 | ||||
-rw-r--r-- | yaksh/templates/yaksh/grade_user.html | 14 | ||||
-rw-r--r-- | yaksh/templates/yaksh/user_data.html | 17 | ||||
-rw-r--r-- | yaksh/templates/yaksh/view_answerpaper.html | 14 |
4 files changed, 43 insertions, 57 deletions
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() { </thead> <tbody> {% for question, answers in paper.get_question_answers.items %} - {% with answers|last as answer %} <tr> <td> <a href="#question_{{question.id}}"> @@ -327,14 +326,13 @@ function searchNames() { </a> </td> <td>{{ question.type }}</td> - <td>{{ answer.marks }}</td> + <td>{{ answers|last }}</td> <td> <a href="{% url 'yaksh:regrade_by_question' course_id quiz.questionpaper_set.get.id paper.id question.id %}" class="btn btn-outline-success"> <i class="fa fa-repeat"></i> Regrade </a> </td> </tr> - {% endwith %} {% endfor %} </tbody> </table> @@ -437,7 +435,10 @@ function searchNames() { </center> {% endif %} <!-- End has_user_assignments --> {% else %} - {% for ans in answers %} + {% if answers|first is None %} + <p> Did not attempt </p> + {% else %} + {% for ans in answers|slice:":-1" %} <strong> Attempt Number: {{forloop.counter}} </strong> @@ -559,6 +560,7 @@ function searchNames() { </div> <br> {% endfor %} <!-- End for ans in answers --> + {% endif %}<!-- check if attempted --> </div> </div> {% endif %} @@ -566,9 +568,7 @@ function searchNames() { <div class="form-group"> <div class="col-md-2"> <label class="col-form-label" for="q{{ question.id }}">Marks:</label> - {% with answers|last as answer %} - <input id="q{{ question.id }}" type="text" name="q{{ question.id }}_marks" size="4" class="form-control" value="{{ answer.marks }}"><br><br> - {% endwith %} + <input id="q{{ question.id }}" type="text" name="q{{ question.id }}_marks" size="4" class="form-control" value="{{ answers|last }}"><br><br> </div> </div> <hr/> 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 @@ <tr> <td>{{question.summary}}</td> <td>{{question.type}}</td> - <td> - {% for answer in answers %} - {{answer.marks}} - {% endfor %} - </td> + <td>{{ answers|last }}</td> </tr> {% endfor %} </tbody> @@ -181,7 +177,11 @@ </center> {% endif %} <!-- End has_user_assignments --> {% else %} - {% for ans in answers %} + + {% if answers|first is None %} + <p> Did not attempt </p> + {% else %} + {% for ans in answers|slice:":-1" %} <strong> Attempt Number: {{forloop.counter}} </strong> @@ -303,6 +303,7 @@ </div> <br> {% endfor %} <!-- End for ans in answers --> + {% endif %}<!-- check if attempted --> </div> </div> {% endif %} @@ -310,9 +311,7 @@ <div class="form-group"> <div class="col-md-2"> <label class="col-form-label" for="q{{ question.id }}">Marks:</label> - {% with answers|last as answer %} - <input id="q{{ question.id }}" type="text" name="q{{ question.id }}_marks" size="4" class="form-control" value="{{ answer.marks }}" readonly=""><br><br> - {% endwith %} + <input id="q{{ question.id }}" type="text" name="q{{ question.id }}_marks" size="4" class="form-control" value="{{ answers|last }}" readonly=""><br><br> </div> </div> <hr/> 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 @@ </thead> <tbody> {% for question, answers in paper.get_question_answers.items %} - {% with answers|last as answer %} <tr> <td> <a href="#question_{{question.id}}"> @@ -88,9 +87,8 @@ </a> </td> <td>{{ question.type }}</td> - <td>{{ answer.answer.marks }}</td> + <td>{{ answers|last }}{{ answer.answer.marks }}</td> </tr> - {% endwith %} {% endfor %} </tbody> </table> @@ -200,7 +198,10 @@ </center> {% endif %} <!-- End has_user_assignments --> {% else %} - {% for ans in answers %} + {% if answers|first is None %} + <p> Did not attempt </p> + {% else %} + {% for ans in answers|slice:":-1" %} <strong> Attempt Number: {{forloop.counter}} </strong> @@ -324,6 +325,7 @@ </div> <br> {% endfor %} <!-- End for ans in answers --> + {% endif %}<!-- check if attempted --> </div> </div> {% endif %} @@ -331,9 +333,7 @@ <div class="form-group"> <div class="col-md-2"> <label class="col-form-label" for="q{{ question.id }}">Marks:</label> - {% with answers|last as answer %} - <input id="q{{ question.id }}" type="text" name="q{{ question.id }}_marks" size="4" class="form-control" value="{{ answer.answer.marks }}" readonly=""><br><br> - {% endwith %} + <input id="q{{ question.id }}" type="text" name="q{{ question.id }}_marks" size="4" class="form-control" value="{{ answers|last }}" readonly=""><br><br> </div> </div> <hr/> |