Changeset - 24239f8ea946
[Not reviewed]
default
0 1 0
Mads Kiilerich - 10 years ago 2015-07-20 15:11:42
madski@unity3d.com
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.
1 file changed with 14 insertions and 14 deletions:
0 comments (0 inline, 0 general)
kallithea/model/db.py
Show inline comments
 
@@ -1512,23 +1512,23 @@ class RepoGroup(Base, BaseModel):
 

	
 
    @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):
0 comments (0 inline, 0 general)