Back to index

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

List of all members.

Public Member Functions

def __call__

Detailed Description

Vocabulary factory for workflow transitions

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

  >>> util(context1) is None
  True

  >>> class Transition(object):
  ...     def __init__(self, id, actbox_name):
  ...         self.id = id
  ...         self.actbox_name = actbox_name

  >>> class TransitionsFolder(object):
  ...     def __init__(self, values):
  ...         self.values = values
  ...
  ...     def objectValues(self):
  ...         return self.values

  >>> class Workflow(object):
  ...     def __init__(self, id, title, values):
  ...         self.id = id
  ...         self.title = title
  ...         self.transitions = TransitionsFolder(values)

  >>> tool = DummyTool('portal_workflow')
  >>> t1 = Transition('publish', 'Publish')
  >>> t2 = Transition('reject', 'Reject')

  >>> wf1 = Workflow('default', 'Default Workflow', (t1, t2))
  >>> wf2 = Workflow('intranet', 'Intranet Workflow', (t1, ))

  >>> def objectValues():
  ...     return (wf1, wf2)
  >>> tool.objectValues = objectValues
  >>> context2.portal_workflow = tool

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

  >>> len(transitions.by_token)
  2

  >>> pub = transitions.by_token['Publish [publish]']
  >>> pub.title, pub.token, pub.value
  (None, 'Publish [publish]', 'publish')

Definition at line 119 of file workflow.py.


Member Function Documentation

Definition at line 178 of file workflow.py.

00178 
00179     def __call__(self, context):
00180         context = getattr(context, 'context', context)
00181         wtool = getToolByName(context, 'portal_workflow', None)
00182         if wtool is None:
00183             return None
00184 
00185         transitions = {}
00186         for wf in wtool.objectValues():
00187             transition_folder = getattr(wf, 'transitions', None)
00188             wf_name = wf.title or wf.id
00189             if transition_folder is not None:
00190                 for transition in transition_folder.objectValues():
00191                     transition_title = transition.actbox_name
00192                     transitions.setdefault(transition.id, []).append(dict(title=transition_title,
00193                                                                         wf_name=wf_name))
00194         items = []
00195         for transition_id, info in transitions.items():
00196             titles = set([i['title'] for i in info])
00197             item_title = ' // '.join(sorted(titles))
00198             items.append(("%s [%s]" % (item_title, transition_id,), transition_id),)
00199 
00200         return SimpleVocabulary.fromItems(sorted(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: