summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorprathamesh2017-09-05 19:27:15 +0530
committerprathamesh2017-09-05 19:27:15 +0530
commit7aac7a18e4e393b7e267d3687be73a7fdfb7b400 (patch)
treee51b00daae53fb0c8e0ba6fb9601222884ccc3d7
parent360af260ed71c40b4ed320baaf6e34f2fef2f694 (diff)
downloadonline_test-7aac7a18e4e393b7e267d3687be73a7fdfb7b400.tar.gz
online_test-7aac7a18e4e393b7e267d3687be73a7fdfb7b400.tar.bz2
online_test-7aac7a18e4e393b7e267d3687be73a7fdfb7b400.zip
Removed redundancy from request handler JS
-rw-r--r--yaksh/live_server_tests/load_test.py4
-rw-r--r--yaksh/models.py2
-rw-r--r--yaksh/static/yaksh/js/requesthandler.js59
3 files changed, 24 insertions, 41 deletions
diff --git a/yaksh/live_server_tests/load_test.py b/yaksh/live_server_tests/load_test.py
index ee4549d..5ab1cc2 100644
--- a/yaksh/live_server_tests/load_test.py
+++ b/yaksh/live_server_tests/load_test.py
@@ -26,7 +26,9 @@ class YakshSeleniumTests(StaticLiveServerTestCase):
"yaksh.cpp_code_evaluator.CppCodeEvaluator"
settings.code_evaluators['bash']['standardtestcase'] = \
"yaksh.bash_code_evaluator.BashCodeEvaluator"
- code_server_pool = ServerPool(n=settings.N_CODE_SERVERS, pool_port=settings.SERVER_POOL_PORT)
+ code_server_pool = ServerPool(
+ n=settings.N_CODE_SERVERS, pool_port=settings.SERVER_POOL_PORT
+ )
cls.code_server_pool = code_server_pool
cls.code_server_thread = t = Thread(target=code_server_pool.run)
t.start()
diff --git a/yaksh/models.py b/yaksh/models.py
index 7198e69..3697c78 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -1356,7 +1356,7 @@ class AnswerPaper(models.Model):
user_dir = self.user.profile.get_user_dir()
url = 'http://localhost:%s' % SERVER_POOL_PORT
submit(url, uid, json_data, user_dir)
- result = {'uid': uid, 'state': 'running'}
+ result = {'uid': uid, 'status': 'running'}
return result
def regrade(self, question_id):
diff --git a/yaksh/static/yaksh/js/requesthandler.js b/yaksh/static/yaksh/js/requesthandler.js
index 9890b54..9e2c2e5 100644
--- a/yaksh/static/yaksh/js/requesthandler.js
+++ b/yaksh/static/yaksh/js/requesthandler.js
@@ -12,7 +12,7 @@ function check_state(state, uid) {
} else if (state == "unknown") {
request_status = "initial";
count = 0;
- notify("You are requesting for a wrong data");
+ notify("Request timeout. Try again later");
clearInterval(checker);
unlock_screen();
} else {
@@ -47,13 +47,23 @@ function check_lock_screen() {
}
function get_result(uid){
+ var url = "/exam/get_results/"+uid+"/";
+ ajax_call(url, "GET", "html", null, uid)
+}
+
+function ajax_call(url, method_type, data_type, data, uid) {
$.ajax({
- method: "GET",
- url: "/exam/get_results/"+uid+"/",
- dataType: "html", // Your server can response html, json, xml format.
+ method: method_type,
+ url: url,
+ data: data,
+ dataType: data_type, // Your server can response html, json, xml format.
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();
@@ -62,6 +72,9 @@ function get_result(uid){
} 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";
@@ -78,6 +91,7 @@ function get_result(uid){
notify("There is some problem. Try later.")
}
});
+
}
var global_editor = {};
@@ -118,41 +132,8 @@ $(document).ready(function(){
$('#code').submit(function(e) {
checker = setInterval(check_lock_screen, 30000);
lock_screen();
- $.ajax({
- type: 'POST',
- url: $(this).attr("action"),
- data: $(this).serializeArray(),
- dataType: "html", // Your server can response html, json, xml format.
- success: function(data, status, xhr) {
- content_type = xhr.getResponseHeader("content-type");
- if(content_type.indexOf("text/html") !== -1) {
- 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);
- var uid = res.uid;
- request_status = res.state;
- check_state(request_status, uid);
- } else {
- request_status = "initial";
- count = 0;
- clearInterval(checker);
- unlock_screen();
- }
- },
- error: function(xhr, text_status, error_thrown ) {
- request_status = "initial";
- count = 0;
- clearInterval(checker);
- unlock_screen();
- notify("There is some problem. Try later.")
- }
- });
+ var data = $(this).serializeArray();
+ ajax_call($(this).attr("action"), "POST", "html", data, null)
e.preventDefault(); // To stop the default form submission.
});
});