Back to index

plone3  3.1.7
Public Member Functions
plone.app.vocabularies.security.RolesVocabulary Class Reference

List of all members.

Public Member Functions

def __call__

Detailed Description

Vocabulary factory for roles in the portal

  >>> from zope.component import queryUtility
  >>> from plone.app.vocabularies.tests.base import DummyContext
  >>> from plone.app.vocabularies.tests.base import DummyTool

  >>> name = 'plone.app.vocabularies.Roles'
  >>> util = queryUtility(IVocabularyFactory, name)
  >>> context1 = DummyContext()
  >>> context2 = DummyContext()
  >>> context1.context = context2

  >>> util(context1) is None
  True

  >>> tool = DummyTool('portal_membership')
  >>> def getPortalRoles():
  ...     return ('Anonymous', 'Manager', 'Ploonies')
  >>> tool.getPortalRoles = getPortalRoles
  >>> context2.portal_membership = tool

  >>> roles = util(context1)
  >>> roles
  <zope.schema.vocabulary.SimpleVocabulary object at ...>

  >>> len(roles.by_token)
  3

  >>> manager = roles.by_token['Manager']
  >>> manager.title, manager.token, manager.value
  ('Manager', 'Manager', 'Manager')

Definition at line 8 of file security.py.


Member Function Documentation

Definition at line 43 of file security.py.

00043 
00044     def __call__(self, context):
00045         context = getattr(context, 'context', context)
00046         mtool = getToolByName(context, 'portal_membership', None)
00047         if mtool is None:
00048             return None
00049         items = list(mtool.getPortalRoles())
00050         items.sort()
00051         items = [SimpleTerm(i, i, i) for i in items]
00052         return SimpleVocabulary(items)

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following file: