Back to index

plone3  3.1.7
Functions
CMFPlone.workflow Namespace Reference

Functions

def ToolWorkflowChain

Function Documentation

def CMFPlone.workflow.ToolWorkflowChain (   context,
  workflow_tool 
)
Looks up the workflow chain by portal type suing a mapping
stored on the tool::

  >>> from Products.CMFPlone.tests.dummy import DummyContent, DummyWorkflowTool
  >>> tool = DummyWorkflowTool()
  >>> content = DummyContent(id='dummy', portal_type='DummyType')

Either an object with a portal_type or the portal_type as a
string.  If we pass in an unknown portal_type we get the default
chain::

  >>> ToolWorkflowChain('A Type', tool)
  ('Default Workflow',)
  >>> tool.setChainForPortalTypes(('A Type',), ('Some Workflow',))
  >>> ToolWorkflowChain('A Type', tool)
  ('Some Workflow',)

When we pass in a piece of content we get similar behavior::

  >>> ToolWorkflowChain(content, tool)
  ('Default Workflow',)
  >>> tool.setChainForPortalTypes(('DummyType',), ('Some Workflow',))
  >>> ToolWorkflowChain(content, tool)
  ('Some Workflow',)

   If we can't figure out a portal_type then we return an empty chain::

  >>> ToolWorkflowChain((), tool)
  ()

Definition at line 10 of file workflow.py.

00010 
00011 def ToolWorkflowChain( context, workflow_tool ):
00012     """Looks up the workflow chain by portal type suing a mapping
00013     stored on the tool::
00014 
00015       >>> from Products.CMFPlone.tests.dummy import DummyContent, DummyWorkflowTool
00016       >>> tool = DummyWorkflowTool()
00017       >>> content = DummyContent(id='dummy', portal_type='DummyType')
00018 
00019     Either an object with a portal_type or the portal_type as a
00020     string.  If we pass in an unknown portal_type we get the default
00021     chain::
00022 
00023       >>> ToolWorkflowChain('A Type', tool)
00024       ('Default Workflow',)
00025       >>> tool.setChainForPortalTypes(('A Type',), ('Some Workflow',))
00026       >>> ToolWorkflowChain('A Type', tool)
00027       ('Some Workflow',)
00028 
00029     When we pass in a piece of content we get similar behavior::
00030 
00031       >>> ToolWorkflowChain(content, tool)
00032       ('Default Workflow',)
00033       >>> tool.setChainForPortalTypes(('DummyType',), ('Some Workflow',))
00034       >>> ToolWorkflowChain(content, tool)
00035       ('Some Workflow',)
00036 
00037    If we can't figure out a portal_type then we return an empty chain::
00038 
00039       >>> ToolWorkflowChain((), tool)
00040       ()
00041 
00042     """
00043     if isinstance(context, basestring):
00044         pt = context
00045     elif hasattr(aq_base(context), 'getPortalTypeName'):
00046         pt = context.getPortalTypeName()
00047     else:
00048        pt = None
00049     if pt is None:
00050         return ()
00051     chain = None
00052 
00053     # Unfortunately we need to rely on a private variable here
00054     cbt = workflow_tool._chains_by_type
00055 
00056     if cbt is not None:
00057         chain = cbt.get(pt, None)
00058     if chain is None:
00059         chain = workflow_tool.getDefaultChainFor(context)
00060         if chain is None:
00061             return ()
00062     return chain
00063 

Here is the caller graph for this function: