A vocabular of permission IDs.
Term values are the permission ID strings except for 'zope.Public', which is the global permission CheckerPublic.
Term titles are the permission ID strings except for 'zope.Public', which is shortened to 'Public'.
Terms are sorted by title except for 'Public', which always appears as the first term.
To illustrate, we need to register the permission IDs vocab:
>>> from zope.app.testing.placelesssetup import setUp, tearDown >>> setUp() >>> from zope.schema.vocabulary import getVocabularyRegistry >>> registry = getVocabularyRegistry() >>> registry.register('Permission Ids', PermissionIdsVocabulary)
We also need to register some sample permission utilities, including the special permission 'zope.Public':
>>> from zope.security.interfaces import IPermission >>> from zope.security.permission import Permission >>> from zope.app.testing import ztapi >>> ztapi.provideUtility(IPermission, Permission('zope.Public'), ... 'zope.Public') >>> ztapi.provideUtility(IPermission, Permission('b'), 'b') >>> ztapi.provideUtility(IPermission, Permission('a'), 'a')
We can now lookup these permissions using the vocabulary:
>>> vocab = registry.get(None, 'Permission Ids')
The non-public permissions 'a' and 'b' are string values:
>>> vocab.getTermByToken('a').value u'a' >>> vocab.getTermByToken('b').value u'b'
However, the public permission value is CheckerPublic:
>>> vocab.getTermByToken('zope.Public').value is CheckerPublic True
and its title is shortened:
>>> vocab.getTermByToken('zope.Public').title u'Public'
The terms are sorted by title except for the public permission, which is listed first:
>>> [term.title for term in vocab] [u'Public', u'a', u'b']
>>> tearDown()
There are no attributes in this class.
createTerm(cls, *args)
Create a single term from data.
Subclasses may override this with a class method that creates a term of the appropriate type from the arguments.
fromItems(cls, items, *interfaces)
Construct a vocabulary from a list of (token, value) pairs.
The order of the items is preserved as the order of the terms in the vocabulary. Terms are created by calling the class method createTerm() with the pair (value, token).
One or more interfaces may also be provided so that alternate widgets may be bound without subclassing.
fromValues(cls, values, *interfaces)
Construct a vocabulary from a simple list.
Values of the list become both the tokens and values of the terms in the vocabulary. The order of the values is preserved as the order of the terms in the vocabulary. Tokens are created by calling the class method createTerm() with the value as the only parameter.
One or more interfaces may also be provided so that alternate widgets may be bound without subclassing.
getTerm(value)
See zope.schema.interfaces.IBaseVocabulary
getTermByToken(token)
See zope.schema.interfaces.IVocabularyTokenized
There are no known subclasses.