Back to index

plone3  3.1.7
Public Member Functions
plone.app.vocabularies.types.UserFriendlyTypesVocabulary Class Reference

List of all members.

Public Member Functions

def __call__

Detailed Description

Vocabulary factory for user friendly portal types.

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

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

  >>> util(context1) is None
  True

  >>> context2.portal_types = DummyTypeTool()
  >>> tool = DummyTool('plone_utils')
  >>> def getUserFriendlyTypes():
  ...     return ('Document', )
  >>> tool.getUserFriendlyTypes = getUserFriendlyTypes
  >>> context2.plone_utils = tool

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

  >>> len(types.by_token)
  1

  >>> doc = types.by_token['Document']
  >>> doc.title, doc.token, doc.value
  ('Page', 'Document', 'Document')

Definition at line 150 of file types.py.


Member Function Documentation

Definition at line 187 of file types.py.

00187 
00188     def __call__(self, context):
00189         context = getattr(context, 'context', context)
00190         ptool = getToolByName(context, 'plone_utils', None)
00191         ttool = getToolByName(context, 'portal_types', None)
00192         if ptool is None or ttool is None:
00193             return None
00194         items = [ (ttool[t].Title(), t)
00195                   for t in ptool.getUserFriendlyTypes() ]
00196         items.sort()
00197         items = [SimpleTerm(i[1], i[1], i[0]) for i in items]
00198         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: