summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@araneo.org>2015-08-31 18:50:29 +0200
committerTimotej Lazar <timotej.lazar@araneo.org>2015-08-31 18:50:29 +0200
commitcf284202b76c94daa0425ac21e6f36182a375ffc (patch)
tree6efc65e7981b32639e19bcd462d31334e4d54b35
parent55e70f4a90ad32bbde58c4f3ad1dc0862739b75e (diff)
Return problems for all languages in list_problems
-rw-r--r--client/__init__.py6
-rw-r--r--server/__init__.py5
-rw-r--r--server/problems.py21
-rw-r--r--wsgi_server.py6
4 files changed, 18 insertions, 20 deletions
diff --git a/client/__init__.py b/client/__init__.py
index 1ac18cd..0e3e06a 100644
--- a/client/__init__.py
+++ b/client/__init__.py
@@ -12,7 +12,6 @@ CodeqManager.register('UserSession')
#CodeqManager.register('get_session_by_id')
#CodeqManager.register('get_or_create_session')
#CodeqManager.register('authenticate_and_create_session')
-#CodeqManager.register('list_problems_in_groups')
CodeqManager.register('Codeq')
m = CodeqManager(address=('localhost', 16231), authkey=b'c0d3q3y')
@@ -31,6 +30,5 @@ def authenticate_and_create_session(username, password):
# return m.authenticate_and_create_session(username, password)
return codeq.authenticate_and_create_session(username, password)
-def list_problems_in_groups(language):
-# return m.list_problems_in_groups(language)
- return codeq.list_problems_in_groups(language)
+def list_problems():
+ return codeq.list_problems()
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:
diff --git a/wsgi_server.py b/wsgi_server.py
index 4acb76d..df3c303 100644
--- a/wsgi_server.py
+++ b/wsgi_server.py
@@ -75,11 +75,7 @@ class ProblemList(CodeqService):
session_is_optional = True
def process(self, js, session):
- language = js.get('language')
- if language is None:
- return {'code': 1, 'message': 'Language was not provided'}
- else:
- return {'code': 0, 'message': 'ok', 'problems': client.list_problems_in_groups(language)}
+ return {'code': 0, 'message': 'ok', 'problems': client.list_problems()}
class Login(CodeqService):
session_is_optional = True