summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/handlers.py10
-rw-r--r--server/user_session.py19
-rw-r--r--web/main.js1
3 files changed, 30 insertions, 0 deletions
diff --git a/server/handlers.py b/server/handlers.py
index 619e2c2..a95f75e 100644
--- a/server/handlers.py
+++ b/server/handlers.py
@@ -254,6 +254,15 @@ class Test(CodeqService):
request.reply({'code': 0, 'message': 'ok', 'hints': hints})
+class GetAttempts(CodeqService):
+ def process(self, request):
+ language = request.data.get('language')
+ if language is None:
+ request.reply({'code': 1, 'message': 'No language specified'})
+ else:
+ request.reply({'code': 0, 'data': request.session.get_attempts(language)})
+
+
class GetCurrentSolution(CodeqService):
def process(self, request):
js = request.data
@@ -313,6 +322,7 @@ incoming_handlers = {
'login': Login(),
'signup': Signup(),
'change_password': ChangePassword(),
+ 'get_attempts': GetAttempts(),
'get_current_solution': GetCurrentSolution(),
'logout': Logout(),
'activity': Activity(),
diff --git a/server/user_session.py b/server/user_session.py
index 8661016..02e1bd4 100644
--- a/server/user_session.py
+++ b/server/user_session.py
@@ -323,6 +323,25 @@ class UserSession(object):
finally:
db.return_connection(conn)
+ def get_attempts(self, language):
+ uid = self.get_uid()
+ conn = db.get_connection()
+ try:
+ cur = conn.cursor()
+ try:
+ cur.execute('''
+ select s.problem_id, s.done
+ from solution s
+ inner join problem p on p.id = s.problem_id
+ inner join language l on p.language_id = l.id
+ where s.codeq_user_id = %s and l.identifier = %s''', (uid, language))
+ return {row[0]: row[1] for row in cur.fetchall()}
+ finally:
+ cur.close()
+ finally:
+ conn.commit()
+ db.return_connection(conn)
+
def get_stat(self):
uid = self.get_uid()
gui_lang = self.get_settings().get('gui_lang', 'en')
diff --git a/web/main.js b/web/main.js
index 374f2fc..15e855a 100644
--- a/web/main.js
+++ b/web/main.js
@@ -243,6 +243,7 @@ var guiHandlers = {
'python_stop': true,
'hint': true,
'test': true,
+ 'get_attempts': true,
'get_current_solution': true,
'update_settings': true,
'load_problem': true,