diff options
Diffstat (limited to 'db')
-rw-r--r-- | db/models.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/db/models.py b/db/models.py index e4b5317..f5c690d 100644 --- a/db/models.py +++ b/db/models.py @@ -26,24 +26,27 @@ class CodeqUser(collections.namedtuple('CodeqUser', ['id', 'username', 'password def solved_problems(user_id, language): return _run_sql('select g.identifier, p.identifier from solution s inner join problem p on p.id = s.problem_id inner join problem_group g on g.id = p.problem_group_id inner join language l on l.id = p.language_id where s.codeq_user_id = %s and l.identifier = %s and s.done = True', (user_id, language), fetch_one=False) -class Problem(collections.namedtuple('Problem', ['id', 'language_id', 'problem_group_id', 'identifier'])): - __sql_prefix = 'select id, language_id, problem_group_id, identifier from problem' +class Problem(collections.namedtuple('Problem', ['id', 'language', 'group', 'identifier'])): + __sql_prefix = '''\ + select p.id, l.identifier, g.identifier, p.identifier + from problem p + inner join problem_group g on g.id = p.problem_group_id + inner join language l on l.id = p.language_id''' + __sql_order = 'p.language_id, p.problem_group_id, p.id' @staticmethod def get(**kwargs): + kwargs = {'p.'+k: v for k, v in kwargs.items()} return _general_get(kwargs, Problem, Problem.__sql_prefix) @staticmethod def list(): - return _general_list(Problem, Problem.__sql_prefix, order='language_id, problem_group_id, id') + return _general_list(Problem, Problem.__sql_prefix, order=Problem.__sql_order) @staticmethod def filter(**kwargs): - return _general_filter(kwargs, Problem, Problem.__sql_prefix) - - @staticmethod - def get_identifier(problem_id): - return _run_sql('select l.identifier, g.identifier, p.identifier from problem p inner join problem_group g on g.id = p.problem_group_id inner join language l on l.id = p.language_id where p.id = %s', (problem_id,), fetch_one=True) + kwargs = {'p.'+k: v for k, v in kwargs.items()} + return _general_filter(kwargs, Problem, Problem.__sql_prefix, order=Problem.__sql_order) # known as Attempt in the original code class Solution(collections.namedtuple('Solution', ['id', 'done', 'content', 'problem_id', 'codeq_user_id', 'trace'])): |