[Erp5-report] r30539 - /erp5/trunk/products/ERP5Type/patches/WorkflowTool.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Thu Nov 12 20:49:18 CET 2009
Author: leonardo
Date: Thu Nov 12 20:49:17 2009
New Revision: 30539
URL: http://svn.erp5.org?rev=30539&view=rev
Log:
reimplement WorkflowMethod in CMFCore
Modified:
erp5/trunk/products/ERP5Type/patches/WorkflowTool.py
Modified: erp5/trunk/products/ERP5Type/patches/WorkflowTool.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/patches/WorkflowTool.py?rev=30539&r1=30538&r2=30539&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/patches/WorkflowTool.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/patches/WorkflowTool.py [utf8] Thu Nov 12 20:49:17 2009
@@ -785,3 +785,43 @@
WorkflowTool._reindexWorkflowVariables = lambda self, ob: \
hasattr(aq_base(ob), 'reindexObjectSecurity') and ob.reindexObjectSecurity()
+
+# Backward compatibility, as WorkflowMethod has been removed in CMFCore 2.2
+from MethodObject import Method
+class WorkflowMethod( Method ):
+
+ """ Wrap a method to workflow-enable it.
+ """
+ _need__name__=1
+
+ def __init__(self, method, id=None, reindex=1):
+ self._m = method
+ if id is None:
+ id = method.__name__
+ self._id = id
+ # reindex ignored since workflows now perform the reindexing.
+
+ def __call__(self, instance, *args, **kw):
+
+ """ Invoke the wrapped method, and deal with the results.
+ """
+ wf = getToolByName(instance, 'portal_workflow', None)
+ if wf is None or not hasattr(wf, 'wrapWorkflowMethod'):
+ # No workflow tool found.
+ try:
+ res = self._m(instance, *args, **kw)
+ except ObjectDeleted, ex:
+ res = ex.getResult()
+ else:
+ if hasattr(aq_base(instance), 'reindexObject'):
+ instance.reindexObject()
+ else:
+ res = wf.wrapWorkflowMethod(instance, self._id, self._m,
+ (instance,) + args, kw)
+
+try:
+ from Products.CMFCore.WorkflowCore import WorkflowMethod
+except ImportError:
+ from Products.CMFCore import WorkflowCore
+ # We're on CMF 2, where WorkflowMethod has been removed from CMFCore
+ WorkflowCore.WorkflowMethod = WorkflowCore.WorkflowAction = WorkflowMethod
More information about the Erp5-report
mailing list