[CMF-checkins] CVS: CMF/CMFCore - WorkflowTool.py:1.22
Tres Seaver
tseaver@zope.com
Fri, 29 Mar 2002 18:43:39 -0500
Update of /cvs-repository/CMF/CMFCore
In directory cvs.zope.org:/tmp/cvs-serv16719
Modified Files:
WorkflowTool.py
Log Message:
- Add new test suite for WorkflowTool (still not complete coverage).
- WorkflowTool:
o Add interface assertion, and reorganize method order to make
interface conformance clearer.
o Make 'getChainFor' more robust in the face of non-content.
o Add "cleanup" of workflow factory registry (to ease testing).
=== CMF/CMFCore/WorkflowTool.py 1.21 => 1.22 === (457/557 lines abridged)
from Acquisition import aq_base, aq_inner, aq_parent
from WorkflowCore import WorkflowException, ObjectDeleted, ObjectMoved
-import CMFCorePermissions
+from CMFCorePermissions import ManagePortal
from string import join, split, replace, strip
+from interfaces.portal_workflow import portal_workflow
+
AUTO_MIGRATE_WORKFLOW_TOOLS = 0 # Set to 1 to auto-migrate
@@ -55,6 +57,7 @@
'''
id = 'portal_workflow'
meta_type = 'CMF Workflow Tool'
+ __implements__ = portal_workflow
_chains_by_type = None # PersistentMapping
_default_chain = ('default_workflow',)
@@ -70,8 +73,7 @@
#
# ZMI methods
#
- security.declareProtected( CMFCorePermissions.ManagePortal
- , 'manage_overview' )
+ security.declareProtected( ManagePortal, 'manage_overview' )
manage_overview = DTMLFile( 'explainWorkflowTool', _dtmldir )
if AUTO_MIGRATE_WORKFLOW_TOOLS:
@@ -94,8 +96,7 @@
_manage_addWorkflowForm = DTMLFile('addWorkflow', _dtmldir)
- security.declareProtected( CMFCorePermissions.ManagePortal
- , 'manage_addWorkflowForm')
+ security.declareProtected( ManagePortal, 'manage_addWorkflowForm')
def manage_addWorkflowForm(self, REQUEST):
'''
Form for adding workflows.
@@ -106,8 +107,7 @@
wft.sort()
return self._manage_addWorkflowForm(REQUEST, workflow_types=wft)
- security.declareProtected( CMFCorePermissions.ManagePortal
- , 'manage_addWorkflow')
+ security.declareProtected( ManagePortal, 'manage_addWorkflow')
def manage_addWorkflow(self, workflow_type, id, RESPONSE=None):
'''
Adds a workflow from the registered types.
@@ -123,19 +123,11 @@
[-=- -=- -=- 457 lines omitted -=- -=- -=-]
+ if wf_ids:
+ changed = 0
+ for wf_id in wf_ids:
+ wf = wfs.get(wf_id, None)
+ if wf is not None:
+ did = wf.updateRoleMappingsFor(ob)
+ if did: changed = 1
+ if changed:
+ count = count + 1
+ if hasattr(aq_base(ob), 'objectItems'):
+ obs = ob.objectItems()
+ if obs:
+ for k, v in obs:
+ changed = getattr(v, '_p_changed', 0)
+ count = count + self._recursiveUpdateRoleMappings(v, wfs)
+ if changed is None:
+ # Re-ghostify.
+ v._p_deactivate()
+ return count
+
InitializeClass(WorkflowTool)
_workflow_factories = {}
-def addWorkflowFactory(factory, id=None, title=None):
+def _makeWorkflowFactoryKey(factory, id=None, title=None):
# The factory should take one argument, id.
if id is None:
id = getattr(factory, 'id', '') or getattr(factory, 'meta_type', '')
@@ -623,7 +635,19 @@
key = id
if title:
key = key + ' (%s)' % title
+ return key
+
+def addWorkflowFactory(factory, id=None, title=None):
+ key = _makeWorkflowFactoryKey( factory, id, title )
_workflow_factories[key] = factory
addWorkflowClass = addWorkflowFactory # bw compat.
+
+def _removeWorkflowFactory( factory, id=None, title=None ):
+ """ Make teardown in unitcase cleaner. """
+ key = _makeWorkflowFactoryKey( factory, id, title )
+ try:
+ del _workflow_factories[key]
+ except KeyError:
+ pass