From 0e56fc6a77ec21db05c9bafb42b1acc652354a32 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Thu, 22 Dec 2016 20:16:00 +0530 Subject: - Fix grade user rendering issue when question is skipped - Modify grade user html template to create readable variables for answer and error --- yaksh/models.py | 10 ++++++++-- yaksh/python_assertion_evaluator.py | 2 +- yaksh/templates/yaksh/grade_user.html | 26 +++++--------------------- yaksh/templates/yaksh/question.html | 24 ++++++++++++++++++++---- yaksh/test_models.py | 5 +++-- yaksh/views.py | 5 +++-- 6 files changed, 40 insertions(+), 32 deletions(-) diff --git a/yaksh/models.py b/yaksh/models.py index 08feab6..35999d3 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -1027,9 +1027,15 @@ class AnswerPaper(models.Model): for answer in self.answers.all(): question = answer.question if question in q_a: - q_a[question].append((answer, [e for e in json.loads(answer.error)])) + q_a[question].append({'answer': answer, + 'error_list': [e for e in json.loads(answer.error)] + } + ) else: - q_a[question] = [(answer, [e for e in json.loads(answer.error)])] + q_a[question] = [{'answer': answer, + 'error_list': [e for e in json.loads(answer.error)] + } + ] return q_a def get_questions(self): diff --git a/yaksh/python_assertion_evaluator.py b/yaksh/python_assertion_evaluator.py index d8cd07c..749a6ec 100644 --- a/yaksh/python_assertion_evaluator.py +++ b/yaksh/python_assertion_evaluator.py @@ -77,7 +77,7 @@ class PythonAssertionEvaluator(BaseEvaluator): fname, lineno, func, text = info[-1] text = str(self.test_case) err = "Expected Test Case:\n{0}\n" \ - "Error - {1} {2} in: {3}\n-----".format( + "Error - {1} {2} in: {3}\n".format( self.test_case, type.__name__, str(value), diff --git a/yaksh/templates/yaksh/grade_user.html b/yaksh/templates/yaksh/grade_user.html index 516a6d0..6fb8187 100644 --- a/yaksh/templates/yaksh/grade_user.html +++ b/yaksh/templates/yaksh/grade_user.html @@ -118,6 +118,7 @@ Status : Passed
method="post"> {% csrf_token %} {% for question, answers in paper.get_question_answers.items %} +
Details: {{forloop.counter}}. {{ question.summary }} @@ -139,39 +140,22 @@ Status : Passed
{%endif%}
- {% if question.type == "mcq" or question.type == "mcc" %} - {% if "Correct answer" in answers.0.error %} -
- {% else %} -
- {% endif %} -
- Autocheck: {{ answers.0.error }} -
-
-
Student answer:
-
{{forloop.counter}}. {{ answers.0 }}
-
-
- {% else %}
Student answer:
- {% for answer in answers %} - {% if answer.0.correct %} + {% for ans in answers %} + {% if ans.answer.correct %}
Correct: {% else %}
Error: {% endif %} - {% for err in answer.1 %} + {% for err in ans.error_list %}
{{ err }}
{% endfor %}
-
{{ answer.0.answer.strip }}
+
{{ ans.answer.answer.strip }}
- {% endif %} {% endfor %} - {% endif %} {% with answers|last as answer %} Marks: {% if question.type == "mcq" %} {% if error_message %} -

{{ error_message }}

- {% endif %} +

+

+
+ {% for err in error_message %} + {{ err }} + {% endfor %} +
+
+

+ {% endif %} {% for test_case in test_cases %} {{ test_case.options }}
{% endfor %} {% endif %} {% if question.type == "mcc" %} {% if error_message %} -

{{ error_message }}

- {% endif %} +

+

+
+ {% for err in error_message %} + {{ err }} + {% endfor %} +
+
+

+ {% endif %} {% for test_case in test_cases %} {{ test_case.options }}
diff --git a/yaksh/test_models.py b/yaksh/test_models.py index e5bd104..6764dd0 100644 --- a/yaksh/test_models.py +++ b/yaksh/test_models.py @@ -730,8 +730,9 @@ class AnswerPaperTestCases(unittest.TestCase): """ Test get_question_answer() method of Answer Paper""" answered = self.answerpaper.get_question_answers() first_answer = list(answered.values())[0][0] - self.assertEqual(first_answer[0].answer, 'Demo answer') - self.assertTrue(first_answer[0].correct) + first_answer_obj = first_answer['answer'] + self.assertEqual(first_answer_obj.answer, 'Demo answer') + self.assertTrue(first_answer_obj.correct) self.assertEqual(len(answered), 2) def test_is_answer_correct(self): diff --git a/yaksh/views.py b/yaksh/views.py index 35121e7..7ecf6aa 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -430,7 +430,8 @@ def skip(request, q_id, next_q=None, attempt_num=None, questionpaper_id=None): if request.method == 'POST' and question.type == 'code': user_code = request.POST.get('answer') new_answer = Answer(question=question, answer=user_code, - correct=False, skipped=True) + correct=False, skipped=True, + error=json.dumps([])) new_answer.save() paper.answers.add(new_answer) if next_q is not None: @@ -479,7 +480,7 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None): msg = ["Please submit a valid option or code"] return show_question(request, current_question, paper, msg) new_answer = Answer(question=current_question, answer=user_answer, - correct=False) + correct=False, error=json.dumps([])) new_answer.save() paper.answers.add(new_answer) # If we were not skipped, we were asked to check. For any non-mcq -- cgit