diff options
-rw-r--r-- | instances.py | 12 | ||||
-rw-r--r-- | static/website/js/cloud.js | 19 | ||||
-rw-r--r-- | tornado_main.py | 6 |
3 files changed, 17 insertions, 20 deletions
diff --git a/instances.py b/instances.py index dd909f7..9eebbd0 100644 --- a/instances.py +++ b/instances.py @@ -16,12 +16,13 @@ from django.template.loader import render_to_string, get_template from django.core.mail import EmailMultiAlternatives # importing the local variables from R_on_Cloud.settings import PROJECT_DIR -from R_on_Cloud.config import (BIN, API_URL) +from R_on_Cloud.config import (BIN, API_URL, API_URL_PLOT) -def execute_code(code, session_id): +def execute_code(code, session_id, R_file_id): #session_id = self.request.session['session_id'] # Check for system commands + system_commands = re.compile( r'unix\(.*\)|unix_g\(.*\)|unix_w\(.*\)|' r'unix_x\(.*\)|unix_s\(.*\)|host|newfun' @@ -37,6 +38,7 @@ def execute_code(code, session_id): body = { 'code': code, 'session_id': session_id, + 'R_file_id': R_file_id, } req = urllib.request.Request(API_URL) req.add_header('Content-Type', 'application/json; charset=utf-8') @@ -47,8 +49,12 @@ def execute_code(code, session_id): result = urllib.request.urlopen(req, jsondataasbytes) result = result.read().decode("utf8") output = json.loads(result)["output"] + graph_exist = json.loads(result)["graph_exist"] + graph_path = API_URL_PLOT + "?session_id=" + session_id +"&R_file_id="+ R_file_id data = { - 'output': output + 'output': output, + 'graph_exist': graph_exist, + 'graph_path': graph_path, } return data diff --git a/static/website/js/cloud.js b/static/website/js/cloud.js index b8ed180..fc0bbfc 100644 --- a/static/website/js/cloud.js +++ b/static/website/js/cloud.js @@ -37,6 +37,7 @@ function checkInput(){ } /**************************** math captcha function end *******************/ $(document.body).ready(function() { + var editor = CodeMirror.fromTextArea(document.getElementById( "code"), { lineNumbers: true, @@ -650,7 +651,6 @@ $(document.body).ready(function() { $plotbox_wrapper = $("#plotbox_wrapper"); $plotbox = $("#plotbox"); - var baseurl = window.location.origin + window.location.pathname; $(document).on("click", "#execute", function() { if(editor.getValue() != ""){ ajax_loader(this); @@ -660,6 +660,7 @@ $(document.body).ready(function() { "[name='csrfmiddlewaretoken']" ).val(), session_id: $("#session_id").val() || 0, + R_file_id: $("#R_file_id").val() || 0, code: editor.getValue(), book_id: $("#books").val() || 0, chapter_id: $("#chapters").val() || 0, @@ -672,18 +673,10 @@ $(document.body).ready(function() { "Execute"); ajax_loader('clear'); result.setValue(data.output); - pp = baseurl + data.plot_path.slice(1); - url = pp; - if (data.plot_path) { - $.ajax({ - type: "HEAD", - async: true, - url: pp, - }).done(function() { - if( data.plot_path != 0){ + if(data.graph_exist){ $plot = $("<img>"); $plot.attr({ - src: data.plot_path, + src: data.graph_path, width: '100%' }); $plotbox.html($plot); @@ -697,10 +690,8 @@ $(document.body).ready(function() { "download", dt + '.png'); $("#plot_download").attr( - "href", data.plot_path + "href", data.graph_path ); - } - }); } }); }else{ diff --git a/tornado_main.py b/tornado_main.py index 9d2b493..8b542a9 100644 --- a/tornado_main.py +++ b/tornado_main.py @@ -121,9 +121,9 @@ class ExecutionHandler(tornado.web.RequestHandler): global request_count request_count += 1 session_id = self.request.arguments['session_id'][0].decode('UTF-8') - code = self.request.arguments['code'][0] - code = code.decode('UTF-8') - data = yield executor.submit(execute_code, code, session_id,) + R_file_id = str(time.time()) + code = self.request.arguments['code'][0].decode('UTF-8') + data = yield executor.submit(execute_code, code, session_id, R_file_id) self.write(data) request_count -= 1 |