[Zope-Coders] Re: [Zope3-checkins] SVN: Zope3/trunk/src/ Modified 'Permission Ids' vocabulary:

Florent Guillaume fg at nuxeo.com
Thu Jul 8 11:11:26 EDT 2004


> Log message for revision 26177:
> Modified 'Permission Ids' vocabulary:
> 
> - CheckerPublic is the value for permission ID 'zope.Public'
> - 'Public' is the display name (title) instead of 'zope.Public'
> - Vocabulary list is sorted alphabetically except that Public appears as first item
> 
> Change also includes modifications to test code to properly reset the vocabulary registry per test setup.
> 
> This fixes http://collector.zope.org/Zope3-dev/219
[snip]
> Added: Zope3/trunk/src/zope/app/security/vocabulary.py
> ===================================================================
[snip]
> +    def __init__(self, context):
> +        terms = []
> +        permissions = zapi.getUtilitiesFor(IPermission, context)
> +        for name, permission in permissions:
> +            if name == 'zope.Public':
> +                terms.append(SimpleTerm(
> +                    CheckerPublic, 'zope.Public', u'Public'))
> +            else:
> +                terms.append(SimpleTerm(name, name, name))
> +        super(PermissionIdsVocabulary, self).__init__(terms)
> +        terms.sort(lambda lhs, rhs: \
> +            lhs.title == u'Public' and -1 or cmp(lhs.title, rhs.title))

This kind of sorting is not optimal, it's much better to do a Schwartz
transform. And here where you only have one special case I think I'd do
the sort without it and add it by hand at the start afterwards.

I don't know if this piece of code is time-critical though.

Florent





-- 
Florent Guillaume, Nuxeo (Paris, France)
+33 1 40 33 79 87  http://nuxeo.com  mailto:fg at nuxeo.com


More information about the Zope-Coders mailing list