# HG changeset patch # User Søren Løvborg # Date 2016-09-15 15:13:27 # Node ID 590d5b7a2b26319d5914855ba189499bd92b0169 # Parent 0b7b8e8031e681319e5edbf9a43b8597149f8d9e db: do case-insensitive explicit sorting of RepoGroup names This does not change the implicit sorting enabled via __mapper_args__, which is a bad idea anyway (and now deprecated), and will have to be dealt with in a later changeset. The use of __mapper_args__ implicitly adds sorting to every query of RepoGroup objects throughout the code (including implicit queries via relationships). For the relationships, __mapper_args can be replaced with "order_by" on each individual relationship, and it's reasonably straight-forward to identify every RepoGroup query throughout the code, and add explicit sorting. But we don't really need that sorting most of the time, so a better way forward may be to identify all the places that actually needs the sorting, make it explicit there, and then kill the __mapper_args__. (Anyway, future work.) diff --git a/kallithea/controllers/admin/repo_groups.py b/kallithea/controllers/admin/repo_groups.py --- a/kallithea/controllers/admin/repo_groups.py +++ b/kallithea/controllers/admin/repo_groups.py @@ -303,8 +303,7 @@ class RepoGroupsController(BaseControlle #overwrite our cached list with current filter c.repo_cnt = 0 - groups = RepoGroup.query().order_by(RepoGroup.group_name) \ - .filter(RepoGroup.group_parent_id == c.group.group_id).all() + groups = RepoGroup.query(sorted=True).filter_by(parent_group=c.group).all() c.groups = self.scm_model.get_repo_groups(groups) c.repos_list = Repository.query(sorted=True).filter_by(group=c.group).all() diff --git a/kallithea/controllers/home.py b/kallithea/controllers/home.py --- a/kallithea/controllers/home.py +++ b/kallithea/controllers/home.py @@ -74,7 +74,7 @@ class HomeController(BaseController): log.debug('generating switcher repo/groups list') all_repos = Repository.query(sorted=True).all() repo_iter = self.scm_model.get_repos(all_repos) - all_groups = RepoGroup.query().order_by(RepoGroup.group_name).all() + all_groups = RepoGroup.query(sorted=True).all() repo_groups_iter = self.scm_model.get_repo_groups(all_groups) res = [{ diff --git a/kallithea/model/db.py b/kallithea/model/db.py --- a/kallithea/model/db.py +++ b/kallithea/model/db.py @@ -1518,7 +1518,7 @@ class RepoGroup(Base, BaseModel): CheckConstraint('group_id != group_parent_id', name='ck_groups_no_self_parent'), _table_args_default_dict, ) - __mapper_args__ = {'order_by': 'group_name'} + __mapper_args__ = {'order_by': 'group_name'} # TODO: Deprecated as of SQLAlchemy 1.1. SEP = ' » '