From 95ab26a3b3ee15f0d75dbb87982ec6de8332a395 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Thu, 15 Oct 2015 13:22:47 +0200 Subject: Sort rows by language and group in Problem.list --- db/models.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'db') diff --git a/db/models.py b/db/models.py index 5fa9ffc..e4b5317 100644 --- a/db/models.py +++ b/db/models.py @@ -35,7 +35,7 @@ class Problem(collections.namedtuple('Problem', ['id', 'language_id', 'problem_g @staticmethod def list(): - return _general_list(Problem, Problem.__sql_prefix) + return _general_list(Problem, Problem.__sql_prefix, order='language_id, problem_group_id, id') @staticmethod def filter(**kwargs): @@ -90,7 +90,7 @@ def _general_get(kwargs_dict, clazz, sql_select, row_conversion_fn=_no_row_conve conn.commit() return_connection(conn) -def _general_filter(kwargs_dict, clazz, sql_select, row_conversion_fn=_no_row_conversion): +def _general_filter(kwargs_dict, clazz, sql_select, row_conversion_fn=_no_row_conversion, order='id'): conditions = [] parameters = [] for field_name, field_value in kwargs_dict.items(): @@ -103,7 +103,7 @@ def _general_filter(kwargs_dict, clazz, sql_select, row_conversion_fn=_no_row_co cur = conn.cursor('crsr2') # a named cursor: scrolling is done on the server cur.arraysize = 10000 # scroll unit in the number of rows try: - cur.execute(sql_select + ' where ' + ' and '.join(conditions) + ' order by id', parameters) + cur.execute(sql_select + ' where ' + ' and '.join(conditions) + ' order by ' + order, parameters) result = [] row = cur.fetchone() while row: @@ -116,13 +116,13 @@ def _general_filter(kwargs_dict, clazz, sql_select, row_conversion_fn=_no_row_co conn.commit() return_connection(conn) -def _general_list(clazz, sql_select, row_conversion_fn=_no_row_conversion): +def _general_list(clazz, sql_select, row_conversion_fn=_no_row_conversion, order='id'): conn = get_connection() try: cur = conn.cursor('crsr3') # a named cursor: scrolling is done on the server cur.arraysize = 10000 # scroll unit in the number of rows try: - cur.execute(sql_select + ' order by id') + cur.execute(sql_select + ' order by ' + order) result = [] row = cur.fetchone() while row: -- cgit v1.2.1