summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml3
-rw-r--r--yaksh/static/yaksh/js/requesthandler.js92
-rw-r--r--yaksh/urls.py2
-rw-r--r--yaksh/views.py8
4 files changed, 49 insertions, 56 deletions
diff --git a/.travis.yml b/.travis.yml
index b2d2a58..153f89b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -26,5 +26,8 @@ after_success:
- coverage combine
- coverage report
+dist:
+ precise
+
addons:
firefox: "46.0"
diff --git a/yaksh/static/yaksh/js/requesthandler.js b/yaksh/static/yaksh/js/requesthandler.js
index 9e2c2e5..73d0405 100644
--- a/yaksh/static/yaksh/js/requesthandler.js
+++ b/yaksh/static/yaksh/js/requesthandler.js
@@ -1,34 +1,34 @@
-request_status = "initial"
+request_status = "initial";
count = 0;
-checker = null
+
function submitRequest(){
document.forms["code"].submit();
}
+function reset_values() {
+ request_status = "initial";
+ count = 0;
+}
function check_state(state, uid) {
if ((state == "running" || state == "not started") && count < 7) {
count++;
setTimeout(function() {get_result(uid);}, 2000);
} else if (state == "unknown") {
- request_status = "initial";
- count = 0;
+ reset_values();
notify("Request timeout. Try again later");
- clearInterval(checker);
unlock_screen();
} else {
- request_status = "initial";
- count = 0;
- notify("Please try after few minutes");
- clearInterval(checker);
+ reset_values()
+ notify("Please try again");
unlock_screen();
}
}
function notify(text) {
- var $notice = document.getElementById("notification");
- $notice.classList.add("alert");
- $notice.classList.add("alert-success");
- $notice.innerHTML = text;
+ var notice = document.getElementById("notification");
+ notice.classList.add("alert");
+ notice.classList.add("alert-success");
+ notice.innerHTML = text;
}
function lock_screen() {
@@ -39,54 +39,45 @@ function unlock_screen() {
document.getElementById("ontop").style.display = "none";
}
-function check_lock_screen() {
- var $ontop_div = document.getElementById("ontop");
- if ($ontop_div.style.display == "block") {
- $ontop_div.style.display = "none";
- }
+function get_result(uid){
+ var url = "/exam/get_result/"+uid+"/";
+ ajax_check_code(url, "GET", "html", null, uid)
}
-function get_result(uid){
- var url = "/exam/get_results/"+uid+"/";
- ajax_call(url, "GET", "html", null, uid)
+function response_handler(method_type, content_type, data, uid){
+ if(content_type.indexOf("text/html") !== -1) {
+ if( method_type === "POST") {
+ reset_values();
+ }
+ unlock_screen();
+ document.open();
+ document.write(data);
+ document.close();
+ } else if(content_type.indexOf("application/json") !== -1) {
+ res = JSON.parse(data);
+ request_status = res.status;
+ if(method_type === "POST") {
+ uid = res.uid;
+ }
+ check_state(request_status, uid);
+ } else {
+ reset_values();
+ unlock_screen();
+ }
}
-function ajax_call(url, method_type, data_type, data, uid) {
+function ajax_check_code(url, method_type, data_type, data, uid) {
$.ajax({
method: method_type,
url: url,
data: data,
- dataType: data_type, // Your server can response html, json, xml format.
+ dataType: data_type,
success: function(data, status, xhr) {
content_type = xhr.getResponseHeader("content-type");
- if(content_type.indexOf("text/html") !== -1) {
- if( method_type === "POST") {
- request_status = "initial";
- count = 0;
- }
- clearInterval(checker);
- unlock_screen();
- document.open();
- document.write(data);
- document.close();
- } else if(content_type.indexOf("application/json") !== -1) {
- res = JSON.parse(data);
- request_status = res.status;
- if(method_type === "POST") {
- uid = res.uid;
- }
- check_state(request_status, uid);
- } else {
- request_status = "initial";
- count = 0;
- clearInterval(checker);
- unlock_screen();
- }
+ response_handler(method_type, content_type, data, uid)
},
error: function(xhr, text_status, error_thrown ) {
- request_status = "initial";
- count = 0;
- clearInterval(checker);
+ reset_values();
unlock_screen();
notify("There is some problem. Try later.")
}
@@ -130,10 +121,9 @@ $(document).ready(function(){
global_editor.editor.clearHistory();
}
$('#code').submit(function(e) {
- checker = setInterval(check_lock_screen, 30000);
lock_screen();
var data = $(this).serializeArray();
- ajax_call($(this).attr("action"), "POST", "html", data, null)
+ ajax_check_code($(this).attr("action"), "POST", "html", data, null)
e.preventDefault(); // To stop the default form submission.
});
});
diff --git a/yaksh/urls.py b/yaksh/urls.py
index 3a15f99..c236640 100644
--- a/yaksh/urls.py
+++ b/yaksh/urls.py
@@ -20,7 +20,7 @@ urlpatterns = [
views.complete),
url(r'^register/$', views.user_register, name="register"),
url(r'^(?P<q_id>\d+)/check/$', views.check),
- url(r'^get_results/(?P<uid>\d+)/$', views.get_results),
+ url(r'^get_result/(?P<uid>\d+)/$', views.get_result),
url(r'^(?P<q_id>\d+)/check/(?P<attempt_num>\d+)/(?P<questionpaper_id>\d+)/$',\
views.check),
url(r'^(?P<q_id>\d+)/skip/(?P<attempt_num>\d+)/(?P<questionpaper_id>\d+)/$',
diff --git a/yaksh/views.py b/yaksh/views.py
index 0b601f2..97da29c 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -31,7 +31,7 @@ except ImportError:
from io import BytesIO as string_io
import re
# Local imports.
-from yaksh.code_server import get_result, SERVER_POOL_PORT
+from yaksh.code_server import get_result as get_result_from_code_server, SERVER_POOL_PORT
from yaksh.models import (
Answer, AnswerPaper, AssignmentUpload, Course, FileUpload, FloatTestCase,
HookTestCase, IntegerTestCase, McqTestCase, Profile,
@@ -616,7 +616,7 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None):
if current_question.type in ['code', 'upload']:
if paper.time_left() <= 0:
url = 'http://localhost:%s' % SERVER_POOL_PORT
- result = get_result(url, uid, block=True)
+ result = get_result_from_code_server(url, uid, block=True)
result = json.loads(result.get('result'))
next_question, error_message, paper = _update_paper(request, uid,
result)
@@ -631,10 +631,10 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None):
@csrf_exempt
-def get_results(request, uid):
+def get_result(request, uid):
result = {}
url = 'http://localhost:%s' % SERVER_POOL_PORT
- result_state = get_result(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'))