diff options
-rw-r--r-- | yaksh/static/yaksh/css/exam.css | 2 | ||||
-rw-r--r-- | yaksh/static/yaksh/js/requesthandler.js | 43 | ||||
-rw-r--r-- | yaksh/templates/exam.html | 16 | ||||
-rw-r--r-- | yaksh/templates/yaksh/error_template.html | 93 | ||||
-rw-r--r-- | yaksh/views.py | 26 |
5 files changed, 123 insertions, 57 deletions
diff --git a/yaksh/static/yaksh/css/exam.css b/yaksh/static/yaksh/css/exam.css index ec48a14..7d10629 100644 --- a/yaksh/static/yaksh/css/exam.css +++ b/yaksh/static/yaksh/css/exam.css @@ -4,4 +4,4 @@ table td, table th { border: black solid 1px !important; } #stdio, #assertion { table-layout: fixed -}
\ No newline at end of file +} diff --git a/yaksh/static/yaksh/js/requesthandler.js b/yaksh/static/yaksh/js/requesthandler.js index 1c9a290..5d72241 100644 --- a/yaksh/static/yaksh/js/requesthandler.js +++ b/yaksh/static/yaksh/js/requesthandler.js @@ -61,9 +61,9 @@ function response_handler(method_type, content_type, data, uid){ } else{ unlock_screen(); - error_array = res.error; - generic_error(error_array) - + var error_output = document.getElementById("error_panel"); + error_output.innerHTML = res.error; + focus_on_error(); } } else { reset_values(); @@ -71,35 +71,14 @@ function response_handler(method_type, content_type, data, uid){ } } -function generic_error(error_array){ - var error_output = document.getElementById("error_panel"); - error_output.innerHTML = "" - for (var i = 0; i < error_array.length; i++) { - var panel_danger = document.createElement('div'); - panel_danger.setAttribute('class', "panel panel-danger"); - - var panel_heading = document.createElement('div'); - panel_heading.setAttribute('class', "panel-heading"); - panel_heading.innerHTML = "Error no. " + (i + 1); - - var panel_body = document.createElement('div'); - panel_body.setAttribute('class', "panel-body"); - - var well = document.createElement('div'); - well.setAttribute('class', "well well-sm"); - - var pre = document.createElement('pre'); - var code = document.createElement('code'); - console.log(error_array[i]) - code.append(error_array[i]); - pre.appendChild(code); - well.appendChild(pre); - panel_body.appendChild(well); - panel_danger.appendChild(panel_heading); - panel_danger.appendChild(panel_body); - error_output.appendChild(panel_danger); - } -} +function focus_on_error(){ + var ele = document.getElementById('error_panel') + if (ele) { + ele.scrollIntoView(true); + window.scrollBy(0, -15); + } + } + function ajax_check_code(url, method_type, data_type, data, uid) { $.ajax({ method: method_type, diff --git a/yaksh/templates/exam.html b/yaksh/templates/exam.html index f722c5f..fede185 100644 --- a/yaksh/templates/exam.html +++ b/yaksh/templates/exam.html @@ -33,15 +33,6 @@ </nav><!-- /.navbar --> {% endblock %} {% block content %} - <script> - $(document).ready(function() { - var ele = document.getElementById('error_panel') - if (ele) { - ele.scrollIntoView(true); - window.scrollBy(0, -15); - } - }); - </script> <div class="container-fluid"> <div class="col-sm-3 col-md-2 sidebar"> <p> Question Navigator </p> @@ -80,13 +71,12 @@ {% block main %} {% endblock %} </div> + </div> <br/> + </div> {% if question.type == 'code' or question.type == 'upload' %} - <div class="row" id="error_panel"> - </div> - </div> + <div class="row" id="error_panel"></div> {% endif %} - </div> </div> </div> </div> diff --git a/yaksh/templates/yaksh/error_template.html b/yaksh/templates/yaksh/error_template.html new file mode 100644 index 0000000..d42a259 --- /dev/null +++ b/yaksh/templates/yaksh/error_template.html @@ -0,0 +1,93 @@ +{% block css%} + <link rel="stylesheet" href="{{ URL_ROOT }}/static/yaksh/css/dashboard.css" type="text/css" /> +{% endblock %} + +{% load custom_filters %} + +{% if error_message %} +<div class="col-md-12"> + {% for error in error_message %} + + <div class="panel panel-danger"> + <div class="panel-heading">Error No. {{ forloop.counter }}</div> + <div class="panel-body"> + <div class="well well-sm"> + {% if not error.type %} + <pre><code> {{error|safe}} </code></pre> + + {% elif error.type == 'assertion' %} + + {% if error.test_case %} + <strong> We tried your code with the following test case:</strong> + <br/></br> + <pre><code><strong style="color:#d9534f"> + {{error.test_case}} + </strong></code></pre> + {% endif %} + <p> <b>The following error took place: </b></p> + <table class="table table-bordered" width="100%" id='assertion'> + <col width="30%"> + <tr class = "active"> + <td><b>Exception Name: </b></td> + <td><span style="color: #d9534f">{{error.exception}}</span></td> + </tr> + <tr> + <td><b>Exception Message: </b></td><td>{{error.message}}</td> + </tr> + <tr> + {% if error.traceback %} + <td><b>Full Traceback: </b></td> + <td><pre>{{error.traceback}}</pre></td> + {% endif %} + </tr> + </table> + + {% elif error.type == 'stdio' %} + + {% if error.given_input %} + <table class="table table-bordered"> + <col width="30%"> + <tr class = "active"> + <td> For given Input value(s):</td> + <td>{{error.given_input}}</td> + </tr> + </table> + {% endif %} + + <table class="table table-bordered" width="100%" id="stdio"> + <col width="10%"> + <col width="40%"> + <col width="40%"> + <col width="10%"> + <tr class="info"> + <th><center>Line No.</center></th> + <th><center>Expected Output</center></th> + <th><center>User output</center></th> + <th><center>Status</center></th> + </tr> + {% for expected,user in error.expected_output|zip:error.user_output %} + <td> {{forloop.counter}} </td> + <td>{{expected|default:""}} </td> + <td>{{user|default:""}}</td> + {% if forloop.counter0 in error.error_line_numbers or not expected or not user %} + <td><span class ="glyphicon glyphicon-remove text-warning"/></td> + {% else %} + <td><span class ="glyphicon glyphicon-ok text-success"/></td> + {% endif %} + </tr> + {% endfor %} + </table> + <table width="100%" class='table table-bordered'> + <col width="10"> + <tr class = "danger"> + <td><b>Error:</b></td> + <td>{{error.error_msg}}</td> + </tr> + </table> + {% endif %} + </div> + </div> + </div> + {% endfor %} + </div> +{% endif %}
\ No newline at end of file diff --git a/yaksh/views.py b/yaksh/views.py index dd86e40..29f017e 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -662,19 +662,23 @@ def get_result(request, uid): result['status'] = result_state.get('status') if result['status'] == 'done': result = json.loads(result_state.get('result')) + template_path = os.path.join(*[os.path.dirname(__file__), + 'templates','yaksh', + 'error_template.html' + ] + ) + next_question, error_message, paper = _update_paper(request,uid, + result + ) if result.get('success'): - next_question, error_message, paper = _update_paper(request, - uid, result - ) return show_question(request, next_question, paper, error_message) - # else: - # with open(template_path) as f: - # template_data = f.read() - # template = Template(template_data) - # context = Context(result.get('error')[0]) - # render_error = template.render(context) - # print(render_error) - # result["error"] = render_error + else: + with open(template_path) as f: + template_data = f.read() + template = Template(template_data) + context = Context({"error_message": result.get('error')}) + render_error = template.render(context) + result["error"] = render_error return JsonResponse(result) |