summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@fri.uni-lj.si>2015-10-15 13:22:47 +0200
committerTimotej Lazar <timotej.lazar@fri.uni-lj.si>2015-10-15 13:22:47 +0200
commit95ab26a3b3ee15f0d75dbb87982ec6de8332a395 (patch)
treee905f314b2de55363912110456f7b73012507899 /db
parent25d5189f3a3df361d503e224d89e4ca7531b2d18 (diff)
Sort rows by language and group in Problem.list
Diffstat (limited to 'db')
-rw-r--r--db/models.py10
1 files changed, 5 insertions, 5 deletions
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: