Mailing List Archive

Re: [Zope3-checkins] SVN: Zope3/trunk/src/ Modified 'Permission Ids' vocabulary:
> 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@nuxeo.com
_______________________________________________
Zope-Coders mailing list
Zope-Coders@zope.org
http://mail.zope.org/mailman/listinfo/zope-coders