summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--R_on_Cloud/default_config.py2
-rw-r--r--R_on_Cloud/settings.py2
-rw-r--r--instances.py20
-rw-r--r--static/website/js/cloud.js1
-rw-r--r--static/website/templates/index.html1
-rw-r--r--tornado_main.py6
-rw-r--r--website/views.py5
7 files changed, 22 insertions, 15 deletions
diff --git a/R_on_Cloud/default_config.py b/R_on_Cloud/default_config.py
index 69eaec5..7b56723 100644
--- a/R_on_Cloud/default_config.py
+++ b/R_on_Cloud/default_config.py
@@ -9,6 +9,8 @@ DB_PORT_DEFAULT = ''
BIN = '/usr/bin/R'
+API_URL = "http://127.0.0.1:8001/rscript"
+
SECRET_KEY_STRING = SECRET_KEY
# request_count keeps track of the number of requests at hand, it is incremented
diff --git a/R_on_Cloud/settings.py b/R_on_Cloud/settings.py
index b8babda..f245582 100644
--- a/R_on_Cloud/settings.py
+++ b/R_on_Cloud/settings.py
@@ -134,3 +134,5 @@ STATICFILES_DIRS = [
'/../static/',
]
+
+SESSION_EXPIRE_AT_BROWSER_CLOSE = True
diff --git a/instances.py b/instances.py
index c11aca9..325d760 100644
--- a/instances.py
+++ b/instances.py
@@ -9,19 +9,18 @@ import requests
import json
import urllib.request
import base64
-import uuid
+
from datetime import datetime
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)
-
-URL = "http://127.0.0.1:8001/rscript"
+from R_on_Cloud.config import (BIN, API_URL)
-def execute_code(code, token):
+def execute_code(code, session_id):
+ #session_id = self.request.session['session_id']
# Check for system commands
system_commands = re.compile(
r'unix\(.*\)|unix_g\(.*\)|unix_w\(.*\)|'
@@ -35,12 +34,11 @@ def execute_code(code, token):
code = re.sub(r"View\(", "print(", code)
- session_id = uuid.uuid4()
- user_id = uuid.uuid4()
- body = {'code': code,
- 'user_id': user_id
- }
- req = urllib.request.Request(URL)
+ body = {
+ 'code': code,
+ 'user_id': session_id,
+ }
+ req = urllib.request.Request(API_URL)
req.add_header('Content-Type', 'application/json; charset=utf-8')
jsondata = json.dumps(body)
jsondataasbytes = jsondata.encode('utf-8')
diff --git a/static/website/js/cloud.js b/static/website/js/cloud.js
index 9d99a3c..b8ed180 100644
--- a/static/website/js/cloud.js
+++ b/static/website/js/cloud.js
@@ -659,6 +659,7 @@ $(document.body).ready(function() {
token: $(
"[name='csrfmiddlewaretoken']"
).val(),
+ session_id: $("#session_id").val() || 0,
code: editor.getValue(),
book_id: $("#books").val() || 0,
chapter_id: $("#chapters").val() || 0,
diff --git a/static/website/templates/index.html b/static/website/templates/index.html
index 6653442..56989ab 100644
--- a/static/website/templates/index.html
+++ b/static/website/templates/index.html
@@ -213,6 +213,7 @@
</div>
<textarea id="code" class="form-control" rows="5" placeholder="Write a new code or select existing from above category..." wrap="hard">{{ code }}</textarea>
<br>
+ <input type="hidden" id="session_id" name="session_id" value="{{ session_id }}">
<a id="execute" class="btn btn-dark text-white"><span id="execute-inner">Execute</span></a>
</div>
diff --git a/tornado_main.py b/tornado_main.py
index 5c7c143..388592e 100644
--- a/tornado_main.py
+++ b/tornado_main.py
@@ -120,12 +120,10 @@ class ExecutionHandler(tornado.web.RequestHandler):
def post(self):
global request_count
request_count += 1
-
- token = self.request.arguments['token'][0]
- token = token.decode('UTF-8')
+ session_id = str(self.request.arguments['session_id'][0])
code = self.request.arguments['code'][0]
code = code.decode('UTF-8')
- data = yield executor.submit(execute_code, code, token)
+ data = yield executor.submit(execute_code, code, session_id,)
self.write(data)
request_count -= 1
diff --git a/website/views.py b/website/views.py
index cff15e2..8d63b28 100644
--- a/website/views.py
+++ b/website/views.py
@@ -1,9 +1,14 @@
from django.shortcuts import render
from django.http import HttpResponse
from django.template import loader
+import requests
+import uuid
def index(request):
context = {}
+ session_id = uuid.uuid4()
+ context['session_id'] = str(session_id)
+ request.session['session_id'] = str(session_id)
template = loader.get_template('index.html')
return HttpResponse(template.render(context, request))