diff options
author | Martin <martin@leo.fri1.uni-lj.si> | 2015-09-21 10:13:22 +0200 |
---|---|---|
committer | Martin <martin@leo.fri1.uni-lj.si> | 2015-09-21 10:13:22 +0200 |
commit | 63dff6d770ecb98d7f8f9337449b3450d3abb0de (patch) | |
tree | 3365ea612bb1c4dc4003120ab9d48141add483b4 | |
parent | f352ad0ea7e6e85ab42e56822779a4bf06400f04 (diff) | |
parent | dce8ec719b1d85acf3c753effae3f28629dd847c (diff) |
Merge branch 'master' of ssh://212.235.189.51:22122/codeq-server
-rw-r--r-- | readme.md | 4 | ||||
-rw-r--r-- | server/handlers.py | 7 | ||||
-rw-r--r-- | server/problems.py | 7 | ||||
-rw-r--r-- | server/user_session.py | 3 |
4 files changed, 13 insertions, 8 deletions
@@ -63,8 +63,8 @@ Settings RewriteRule /(.*) ws://localhost:8083/$1 [P,L] ProxyPass /ws/ http://localhost:8083/ws/ ProxyPassReverse /ws/ http://localhost:8083/ws/ - - set _path_prefix in server.problems - - set DB settings in db + - set problems path via environment variable CODEQ_PROBLEMS (defaults to /var/local/codeq-problems) + - set DB settings via environment variables CODEQ_DB_HOST, CODEQ_DB_DATABASE, CODEQ_DB_USER and CODEQ_DB_PASS Running ======= diff --git a/server/handlers.py b/server/handlers.py index 0cc474f..52a33f5 100644 --- a/server/handlers.py +++ b/server/handlers.py @@ -21,7 +21,12 @@ class ProblemList(CodeqService): session_is_optional = True def process(self, request): - request.reply({'code': 0, 'message': 'ok', 'problems': server.problems.list_problems()}) + js = request.data + language = js.get('language') + if language is None: + request.reply({'code': 1, 'message': 'Language was not provided'}) + else: + request.reply({'code': 0, 'message': 'ok', 'problems': server.problems.list_problems(language)}) class Login(CodeqService): diff --git a/server/problems.py b/server/problems.py index 1c87345..220a746 100644 --- a/server/problems.py +++ b/server/problems.py @@ -6,8 +6,7 @@ import threading import os.path 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/' +_path_prefix = os.environ.get('CODEQ_PROBLEMS') or '/var/local/codeq-problems' _module_loading_lock = threading.RLock() # TODO: make a more fine-grained locking import machinery def load_module(fullname): @@ -83,13 +82,13 @@ def solutions_for_problems(language, tuples): pass return '\n'.join(solutions) -def list_problems(): +def list_problems(language): conn = get_connection() try: cur = conn.cursor() try: cur.arraysize = 1000 - 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') + 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 and l.identifier = \''+language+'\' inner join problem_group g on g.id = p.problem_group_id order by l.identifier, g.identifier, p.identifier') result = [] previous_language = '' previous_group = '' diff --git a/server/user_session.py b/server/user_session.py index 0d8535c..00ea039 100644 --- a/server/user_session.py +++ b/server/user_session.py @@ -73,6 +73,7 @@ class UserSession(object): # Get generic and problem-specific hints. hint = dict(mod_language.hint) hint.update(mod.hint) + plan = mod.plan if hasattr(mod, 'plan') else [] conn = db.get_connection() try: @@ -84,7 +85,7 @@ class UserSession(object): result = { 'language': {'id': row[0], 'identifier': language, 'name': row[1]}, 'problem_group': {'id': row[2], 'identifier': problem_group, 'name': row[3]}, - 'problem': {'id': problem_id, 'identifier': problem, 'name': row[5], 'slug': mod.slug, 'description': mod.description, 'hint': hint} + 'problem': {'id': problem_id, 'identifier': problem, 'name': row[5], 'slug': mod.slug, 'description': mod.description, 'hint': hint, 'plan': plan} } cur.execute("select content from solution where problem_id = %s and codeq_user_id = %s", (problem_id, self.uid)) row = cur.fetchone() |