root/cmfblackbird/trunk/workflow.py

Revision 1745, 2.3 kB (checked in by hazmat, 2 years ago)

add missing import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 """
2 a workflow tool implementation that delegates content integration to adapters for workflow
3 chain lookup and state storage.
4
5 $Id$
6 """
7
8 import zope.component
9
10 from Acquisition import aq_base
11 from Globals import PersistentMapping
12 from Products.CMFCore.WorkflowTool import WorkflowTool as BaseTool
13 from Products.CMFCore.utils import getToolByName
14
15 def DefaultWorkflowChain( context, workflow_tool ):
16     print "default chain"
17     if isinstance( context, basestring ):
18         pt = context
19     elif hasattr( aq_base( context ), 'getPortalTypeName'):
20         pt = ob.getPortalTypeName()
21     else:
22         pt = None
23     if pt is None:
24         return ()
25     chain = None
26
27     cbt = workflow_tool._chains_by_type
28    
29     if cbt is not None:
30         chain = cbt.get( pt, None )
31     if chain is None:
32         chain = workflow_tool.getDefaultChainFor( context )
33         if chain is None:
34             return ()
35     return chain
36
37 def DefaultWorkflowState( context ):
38     if hasattr( aq_base, 'workflow_history'):
39         history = ob.workflow_history
40     else:
41         history = PersistentMapping()
42         setattr( ob, 'workflow_history', history )
43     return history
44    
45 def DefaultWorkflowStateQuery( context ):
46     if hasattr( aq_base( ob ), 'workflow_history'):
47         wfh = ob.workflow_history
48     else:
49         wfh = ()
50     return wfh
51
52 class WorkflowTool( BaseTool ):
53
54     def getHistoryOf( self, wf_id, ob ):
55         """
56         Return the history of an object. Invoked by workflow definitions.
57         """
58         wfh = IWorkflowStateQuery( ob )
59         if not wfh:
60             return ()
61         return wfh.get( wf_id, None )
62
63     def setStatusOf( self, wf_id, ob, status ):
64         """
65         Append an entry to the workflow history. Invoked by workflow definitions.
66         """       
67         wfs = IWorkflowState( ob )
68         wfh = wfs.get( wf_id, None )
69         if wfh is not None:
70             wfh = list( wfh )
71         else:
72             wfh = []
73         wfh.append( status )
74         wfs[ wf_id ] = tuple( wfh )
75            
76     def getChainFor( self, ob ):
77         """
78         Returns the chain that applies to the given object.
79         If we get a string as the ob parameter, use it as
80         the portal_type.
81         """
82         return zope.component.queryAdapter( (ob, self), default=() )
83    
Note: See TracBrowser for help on using the browser.