diff options
author | Aleš Smodiš <aless@guru.si> | 2015-08-25 14:20:42 +0200 |
---|---|---|
committer | Aleš Smodiš <aless@guru.si> | 2015-08-25 14:20:42 +0200 |
commit | 88a5cd83b47a9dfb5a832936095c7b99ce0d8179 (patch) | |
tree | a01f0696da1d31201f42242cf61cbc664df65401 /server/problems.py | |
parent | 816d11b6e238e389f84430196bed19d66f49d751 (diff) |
Implemented methods to fetch a list of available problems and the problem description.
JavaScript no longer parses pythonic problem descriptions, instead they are loaded by server and JSONized.
Diffstat (limited to 'server/problems.py')
-rw-r--r-- | server/problems.py | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/server/problems.py b/server/problems.py index 7fb2606..bce72fe 100644 --- a/server/problems.py +++ b/server/problems.py @@ -3,6 +3,7 @@ import sys import importlib.machinery import threading +from db import get_connection, return_connection #sys.path.append('/home/aless/job/codeq/source/codeq-problems/') _path_prefix = '/home/aless/job/codeq/source/codeq-problems/' @@ -45,7 +46,6 @@ def load_problems(language, tuples, tail_module): modules = [] for problem_group, problem in tuples: mod = '{0}.problems.{1}.{2}.{3}'.format(language, problem_group, problem, tail_module) - print('importing {}'.format(mod)) modules.append(load_module(mod)) return modules @@ -81,3 +81,29 @@ def solutions_for_problems(language, tuples): if f: facts.add(f) return '\n'.join(facts) + '\n' + '\n'.join(solutions) + +def list_problems_in_groups(language): + 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,)) + result = [] + previous_group_name = '' + current_sublist = None + row = cur.fetchone() + while row: + current_group_name = row[0] + if previous_group_name != current_group_name: + 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]}) + row = cur.fetchone() + return result + finally: + cur.close() + finally: + conn.commit() + return_connection(conn) |