Back to index

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

List of all members.

Public Member Functions

def __call__

Detailed Description

Vocabulary factory for groups 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.Groups'
  >>> util = queryUtility(IVocabularyFactory, name)
  >>> context1 = DummyContext()
  >>> context2 = DummyContext()
  >>> context1.context = context2

  >>> util(context1) is None
  True

  >>> class DummyGroup(object):
  ...     def __init__(self, id, name):
  ...         self.id = id
  ...         self.name = name
  ...
  ...     def getGroupId(self):
  ...         return self.id
  ...
  ...     def getGroupName(self):
  ...         return self.name

  >>> tool = DummyTool('portal_groups')
  >>> def listGroups():
  ...     return (DummyGroup('editors', 'Editors'),
  ...             DummyGroup('viewers', 'Viewers'))
  >>> tool.listGroups = listGroups
  >>> context2.portal_groups = tool

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

  >>> len(groups.by_token)
  2

  >>> editors = groups.by_token['editors']
  >>> editors.title, editors.token, editors.value
  ('Editors', 'editors', 'editors')

Definition at line 55 of file security.py.


Member Function Documentation

Definition at line 102 of file security.py.

00102 
00103     def __call__(self, context):
00104         context = getattr(context, 'context', context)
00105         gtool = getToolByName(context, 'portal_groups', None)
00106         if gtool is None:
00107             return None
00108         items = [ (g.getGroupId(), g.getGroupName()) for g in gtool.listGroups() ]
00109         items.sort()
00110         items = [SimpleTerm(i[0], i[0], i[1]) for i in items]
00111         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: