# HG changeset patch # User Mads Kiilerich # Date 1437397902 -7200 # Node ID 24239f8ea94638a32447024a543b0e22418cff5f # Parent 346a56c690ffe03540d726e8bbce55b98058ac6f db: cleanup of repo group choices - better handling of root and better sorting groups_choices always get a groups list so there is no reason have code for creating a list. All the responsibility of creating the tuples is moved to _generate_choice - also for the magic top level entries. Also sort the choices by all path elements - not just the top level element. diff -r 346a56c690ff -r 24239f8ea946 kallithea/model/db.py --- a/kallithea/model/db.py Mon Jul 20 15:11:42 2015 +0200 +++ b/kallithea/model/db.py Mon Jul 20 15:11:42 2015 +0200 @@ -1512,23 +1512,23 @@ @classmethod def _generate_choice(cls, repo_group): - from webhelpers.html import literal as _literal - _name = lambda k: _literal(cls.SEP.join(k)) - return repo_group.group_id, _name(repo_group.full_path_splitted) + """Return tuple with group_id as unicode string and name as html literal""" + from webhelpers.html import literal + if repo_group is None: + return (u'-1', u'-- %s --' % _('top level')) + return unicode(repo_group.group_id), literal(cls.SEP.join(repo_group.full_path_splitted)) @classmethod - def groups_choices(cls, groups=None, show_empty_group=True): - if not groups: - groups = cls.query().all() - - repo_groups = [] + def groups_choices(cls, groups, show_empty_group=True): + """Return tuples with group_id as unicode string and name as html literal.""" + if show_empty_group: - repo_groups = [('-1', u'-- %s --' % _('Top level'))] - - repo_groups.extend([cls._generate_choice(x) for x in groups]) - - repo_groups = sorted(repo_groups, key=lambda t: t[1].split(cls.SEP)[0]) - return repo_groups + groups = list(groups) + groups.append(None) + + choices = [cls._generate_choice(g) for g in groups] + + return sorted(choices, key=lambda c: c[1].split(cls.SEP)) @classmethod def url_sep(cls):