summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Zorko <robertz@gurucue.com>2015-09-29 18:16:17 +0200
committerRobert Zorko <robertz@gurucue.com>2015-09-29 18:16:17 +0200
commit6aebfe21975bc74ec713e58339ae40715977e81f (patch)
treeaf84e371508a560615af63b33aa67cfbe67d3381
parent41a0cdf993456d60a1e13d43956d93eed09010bd (diff)
added support to save settings, currently only 'lang' will actually be saved, since it is the only one already in the database
-rw-r--r--server/handlers.py19
-rw-r--r--server/user_session.py19
-rw-r--r--web/main.js5
3 files changed, 43 insertions, 0 deletions
diff --git a/server/handlers.py b/server/handlers.py
index 997e2f2..698ca7d 100644
--- a/server/handlers.py
+++ b/server/handlers.py
@@ -54,6 +54,24 @@ class Login(CodeqService):
request.reply({'code': 0, 'message': 'OK', 'sid':session.get_sid(), 'settings':settings})
+class Settings(CodeqService):
+ def process(self, request):
+ print("Settings yay!")
+ js = request.data
+ settings = js.get('settings')
+ if settings is None:
+ request.reply({'code': 1, 'message': 'New settings not provided'})
+ else:
+ try:
+ request.session.update_settings(settings)
+ request.session.write_settings_to_db()
+ except NoSuchSession:
+ request.reply({'code': 2, 'message': 'No such session'})
+ else:
+ request.reply({'code': 0, 'message': 'OK'})
+
+
+
class Activity(CodeqService):
def process(self, request):
js = request.data
@@ -219,6 +237,7 @@ incoming_handlers = {
'python_push': PythonPush(),
'python_stop': PythonStop(),
'hint': Hint(),
+ 'settings': Settings(),
'test': Test()
}
diff --git a/server/user_session.py b/server/user_session.py
index 6d5af47..3035d77 100644
--- a/server/user_session.py
+++ b/server/user_session.py
@@ -57,6 +57,25 @@ class UserSession(object):
def get_settings(self):
return self.settings
+ def update_settings(self, newSettings):
+ #print("new:"+newSettings)
+ self.settings.update(newSettings)
+
+ def write_settings_to_db(self):
+ conn = db.get_connection()
+ try:
+ cur = conn.cursor()
+ try:
+ #cur.execute("UPDATE codeq_user SET gui_lang='"+self.settings.lang+"' WHERE id="+self.uid)
+ #print(self.settings)
+ print("UPDATE codeq_user SET gui_lang='" + self.settings['lang'] + "' WHERE id="+str(self.uid))
+ finally:
+ cur.close()
+ finally:
+ conn.commit()
+ db.return_connection(conn)
+
+
def get_prolog(self):
with self._access_lock:
if self.prolog_session is None:
diff --git a/web/main.js b/web/main.js
index fb393c8..9f06e88 100644
--- a/web/main.js
+++ b/web/main.js
@@ -160,6 +160,11 @@ var guiHandlers = {
'get_problem': function actionTest(session, message) {
logger.debug('Received get_problem from GUI');
sendDataToPython(message).then(session.send, session.end).done();
+ },
+
+ 'settings': function actionSettings(session, message) {
+ logger.debug('Received settings from GUI');
+ sendDataToPython(message).then(session.send, session.end).done();
}
};