diff options
-rw-r--r-- | yaksh/models.py | 10 | ||||
-rw-r--r-- | yaksh/python_assertion_evaluator.py | 2 | ||||
-rw-r--r-- | yaksh/templates/yaksh/grade_user.html | 26 | ||||
-rw-r--r-- | yaksh/templates/yaksh/question.html | 24 | ||||
-rw-r--r-- | yaksh/test_models.py | 5 | ||||
-rw-r--r-- | 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 : <b style="color: green;"> Passed </b><br/> method="post"> {% csrf_token %} {% for question, answers in paper.get_question_answers.items %} + <div class="panel panel-info"> <div class="panel-heading"> <strong> Details: {{forloop.counter}}. {{ question.summary }} @@ -139,39 +140,22 @@ Status : <b style="color: green;"> Passed </b><br/> {%endif%} </div> </div> - {% if question.type == "mcq" or question.type == "mcc" %} - {% if "Correct answer" in answers.0.error %} - <div class="panel panel-success"> - {% else %} - <div class="panel panel-danger"> - {% endif %} - <div class="panel-heading"> - Autocheck: {{ answers.0.error }} - </div> - <div class="panel-body"> - <h5><u>Student answer:</u></h5> - <pre><code>{{forloop.counter}}. {{ answers.0 }}</code></pre> - </div> - </div> - {% else %} <h5>Student answer: </h5> - {% for answer in answers %} - {% if answer.0.correct %} + {% for ans in answers %} + {% if ans.answer.correct %} <div class="panel panel-success"> <div class="panel-heading">Correct: {% else %} <div class="panel panel-danger"> <div class="panel-heading">Error: {% endif %} - {% for err in answer.1 %} + {% for err in ans.error_list %} <div><pre>{{ err }}</pre></div> {% endfor %} </div> - <div class="panel-body"><pre><code>{{ answer.0.answer.strip }}</code></pre></div> + <div class="panel-body"><pre><code>{{ ans.answer.answer.strip }}</code></pre></div> </div> - {% endif %} {% endfor %} - {% endif %} {% with answers|last as answer %} Marks: <input id="q{{ question.id }}" type="text" name="q{{ question.id }}_marks" size="4" diff --git a/yaksh/templates/yaksh/question.html b/yaksh/templates/yaksh/question.html index c3babaa..0279f0d 100644 --- a/yaksh/templates/yaksh/question.html +++ b/yaksh/templates/yaksh/question.html @@ -162,16 +162,32 @@ function call_skip(url) <div class="panel-body"> {% if question.type == "mcq" %} {% if error_message %} - <p>{{ error_message }}</p> - {% endif %} + <p> + <div class="panel panel-danger"> + <div class="panel-heading"> + {% for err in error_message %} + {{ err }} + {% endfor %} + </div> + </div> + </p> + {% endif %} {% for test_case in test_cases %} <input name="answer" type="radio" value="{{ test_case.options }}" />{{ test_case.options }} <br/> {% endfor %} {% endif %} {% if question.type == "mcc" %} {% if error_message %} - <p>{{ error_message }}</p> - {% endif %} + <p> + <div class="panel panel-danger"> + <div class="panel-heading"> + {% for err in error_message %} + {{ err }} + {% endfor %} + </div> + </div> + </p> + {% endif %} {% for test_case in test_cases %} <input name="answer" type="checkbox" value="{{ test_case.options }}"> {{ test_case.options }} <br> 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 |