Back to index

plone3  3.1.7
Public Member Functions
plone.app.vocabularies.workflow.WorkflowStatesVocabulary Class Reference

List of all members.

Public Member Functions

def __call__

Detailed Description

Vocabulary factory for workflow states.

  >>> 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.WorkflowStates'
  >>> util = queryUtility(IVocabularyFactory, name)
  >>> context1 = DummyContext()
  >>> context2 = DummyContext()
  >>> context1.context = context2

  >>> util(context1) is None
  True

  >>> tool = DummyTool('portal_workflow')
  >>> def listWFStatesByTitle(filter_similar=None):
  ...     return (('Private', 'private'), ('Published', 'published'))
  >>> tool.listWFStatesByTitle = listWFStatesByTitle
  >>> context2.portal_workflow = tool

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

  >>> len(states.by_token)
  2

  >>> pub = states.by_token['published']
  >>> pub.title, pub.token, pub.value
  (u'Published [published]', 'published', 'published')

Definition at line 66 of file workflow.py.


Member Function Documentation

Definition at line 101 of file workflow.py.

00101 
00102     def __call__(self, context):
00103         context = getattr(context, 'context', context)
00104         # XXX This is evil. A vocabulary shouldn't be request specific.
00105         # The sorting should go into a separate widget.
00106         request = aq_get(context, 'REQUEST', None)
00107         wtool = getToolByName(context, 'portal_workflow', None)
00108         if wtool is None:
00109             return None
00110         items = wtool.listWFStatesByTitle(filter_similar=True)
00111         items_dict = dict([(i[1], translate(_(i[0]), context=request)) for i in items])
00112         items_list = [(k, v) for k, v in items_dict.items()]
00113         items_list.sort(lambda x, y: cmp(x[1], y[1]))
00114         terms = [SimpleTerm(k, title=u'%s [%s]' % (v, k)) for k, v in items_list]
00115         return SimpleVocabulary(terms)

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: