A vocabular of role IDs.
Term values are the role ID strings Term are stored by title
To illustrate, we need to register the role IDs vocab:
>>> from zope.app.testing.placelesssetup import setUp, tearDown >>> setUp() >>> from zope.schema.vocabulary import getVocabularyRegistry >>> registry = getVocabularyRegistry() >>> registry.register('Role Ids', RoleIdsVocabulary)
Let's register some sample roles to test against them
>>> from zope.securitypolicy.interfaces import IRole >>> from zope.securitypolicy.role import Role >>> from zope.app.testing import ztapi >>> ztapi.provideUtility(IRole, Role('a_id','a_title'), 'a_id') >>> ztapi.provideUtility(IRole, Role('b_id','b_title'), 'b_id')
Let's lookup the roles using the vocabulary
>>> vocab = registry.get(None, 'Role Ids')
>>> vocab.getTermByToken('a_id').value u'a_id' >>> vocab.getTermByToken('b_id').value u'b_id'
>>> 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.