summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--yaksh/static/yaksh/js/requesthandler.js43
-rw-r--r--yaksh/templates/exam.html83
-rw-r--r--yaksh/views.py26
3 files changed, 64 insertions, 88 deletions
diff --git a/yaksh/static/yaksh/js/requesthandler.js b/yaksh/static/yaksh/js/requesthandler.js
index 7ff90df..1c9a290 100644
--- a/yaksh/static/yaksh/js/requesthandler.js
+++ b/yaksh/static/yaksh/js/requesthandler.js
@@ -53,16 +53,53 @@ function response_handler(method_type, content_type, data, uid){
} else if(content_type.indexOf("application/json") !== -1) {
res = JSON.parse(data);
request_status = res.status;
- if(method_type === "POST") {
- uid = res.uid;
+ if (request_status){
+ if(method_type === "POST") {
+ uid = res.uid;
+ }
+ check_state(request_status, uid);
+ }
+ else{
+ unlock_screen();
+ error_array = res.error;
+ generic_error(error_array)
+
}
- check_state(request_status, uid);
} else {
reset_values();
unlock_screen();
}
}
+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 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 a1f0df4..f722c5f 100644
--- a/yaksh/templates/exam.html
+++ b/yaksh/templates/exam.html
@@ -82,86 +82,9 @@
</div>
<br/>
{% if question.type == 'code' or question.type == 'upload' %}
- {% if error_message %}
- <div class="row" id="error_panel">
- {% 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 %}
+ <div class="row" id="error_panel">
+ </div>
+ </div>
{% endif %}
</div>
</div>
diff --git a/yaksh/views.py b/yaksh/views.py
index bc03ca2..dd86e40 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -8,7 +8,7 @@ from django.http import HttpResponse, JsonResponse
from django.core.urlresolvers import reverse
from django.contrib.auth import login, logout, authenticate
from django.shortcuts import render_to_response, get_object_or_404, redirect
-from django.template import RequestContext
+from django.template import RequestContext, Context, Template
from django.http import Http404
from django.db.models import Sum, Max, Q, F
from django.views.decorators.csrf import csrf_exempt
@@ -44,7 +44,7 @@ from yaksh.forms import (
RandomQuestionForm, QuestionFilterForm, CourseForm, ProfileForm,
UploadFileForm, get_object_form, FileForm, QuestionPaperForm
)
-from .settings import URL_ROOT
+from .settings import URL_ROOT
from .file_utils import extract_files, is_csv
from .send_emails import send_user_mail, generate_activation_key, send_bulk_mail
from .decorators import email_verified, has_profile
@@ -653,13 +653,29 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None):
@csrf_exempt
def get_result(request, uid):
result = {}
+ template_dir = os.path.dirname(os.path.realpath(__file__))
+ template_path = os.path.join(*[template_dir, 'templates',
+ 'yaksh','error_messages.html'
+ ])
url = 'http://localhost:%s' % SERVER_POOL_PORT
- result_state = get_result_from_code_server(url, uid)
+ result_state = get_result_from_code_server(url, uid)
result['status'] = result_state.get('status')
if result['status'] == 'done':
result = json.loads(result_state.get('result'))
- next_question, error_message, paper = _update_paper(request, uid, result)
- return show_question(request, next_question, paper, error_message)
+ 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
+
return JsonResponse(result)