summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2015-10-19 12:19:50 +0200
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2015-10-19 12:19:50 +0200
commit4cce071d7eaf4b18cc5e6c5699646aa52258cb73 (patch)
tree410e4e565e7a0606fd6cdc6491eb0006913b75e6 /server
parent8893bb730b7d4127f1e4f8a47146d5dfb9300c81 (diff)
Add method to return attempted/solved problems for given language
Diffstat (limited to 'server')
-rw-r--r--server/handlers.py10
-rw-r--r--server/user_session.py19
2 files changed, 29 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')