From cf284202b76c94daa0425ac21e6f36182a375ffc Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Mon, 31 Aug 2015 18:50:29 +0200 Subject: Return problems for all languages in list_problems --- server/__init__.py | 5 ++--- server/problems.py | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 11 deletions(-) (limited to 'server') diff --git a/server/__init__.py b/server/__init__.py index 9f2469d..d71f707 100644 --- a/server/__init__.py +++ b/server/__init__.py @@ -23,8 +23,8 @@ class Codeq(object): def authenticate_and_create_session(self, username, password): return user_session.authenticate_and_create_session(username, password) - def list_problems_in_groups(self, language): - return server.problems.list_problems_in_groups(language) + def list_problems(self): + return server.problems.list_problems() class CodeqManager(multiprocessing.managers.BaseManager): pass @@ -37,7 +37,6 @@ CodeqManager.register('UserSession', proxytype=UserSessionProxy) #CodeqManager.register('get_session_by_id', callable=user_session.get_session_by_id, proxytype=UserSessionProxy) #CodeqManager.register('get_or_create_session', callable=user_session.get_or_create_session, proxytype=UserSessionProxy) #CodeqManager.register('authenticate_and_create_session', callable=user_session.authenticate_and_create_session, proxytype=UserSessionProxy) -#CodeqManager.register('list_problems_in_groups', callable=server.problems.list_problems_in_groups) CodeqManager.register('Codeq', callable=Codeq, method_to_typeid=Codeq._method_to_typeid_) def start(): diff --git a/server/problems.py b/server/problems.py index f6f4e45..02f0307 100644 --- a/server/problems.py +++ b/server/problems.py @@ -80,24 +80,29 @@ def solutions_for_problems(language, tuples): pass return '\n'.join(solutions) -def list_problems_in_groups(language): +def list_problems(): conn = get_connection() try: cur = conn.cursor() try: cur.arraysize = 1000 - cur.execute("select g.identifier, g.name, p.identifier, p.name from problem p inner join problem_group g on g.id = p.problem_group_id where p.language_id = (select id from language where identifier = %s) order by g.identifier, p.identifier", (language,)) + cur.execute('select l.identifier, l.name, g.identifier, g.name, p.identifier, p.name from problem p inner join language l on l.id = p.language_id inner join problem_group g on g.id = p.problem_group_id order by l.identifier, g.identifier, p.identifier') result = [] - previous_group_name = '' + previous_language = '' + previous_group = '' current_sublist = None row = cur.fetchone() while row: - current_group_name = row[0] - if previous_group_name != current_group_name: + current_language = row[0] + current_group = row[2] + if previous_language != current_language or previous_group != current_group: current_sublist = [] - result.append({'identifier': current_group_name, 'name': row[1], 'problems': current_sublist}) - previous_group_name = current_group_name - current_sublist.append({'identifier': row[2], 'name': row[3]}) + result.append({'identifier': {'language': current_language, 'group': current_group}, + 'name': {'language': row[1], 'group': row[3]}, + 'problems': current_sublist}) + previous_group = current_group + previous_language = current_language + current_sublist.append({'identifier': row[4], 'name': row[5]}) row = cur.fetchone() return result finally: -- cgit v1.2.1