From 4cce071d7eaf4b18cc5e6c5699646aa52258cb73 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Mon, 19 Oct 2015 12:19:50 +0200 Subject: Add method to return attempted/solved problems for given language --- server/handlers.py | 10 ++++++++++ server/user_session.py | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) (limited to 'server') 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') -- cgit v1.2.1