vendor/CMF/1.6.3/CMFCore

view WorkflowCore.py @ 0:587011552858

import CMF 1.6.3
author bdelbosc
date Mon, 23 Apr 2007 13:58:01 +0000
parents
children
line source
1 ##############################################################################
2 #
3 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
4 #
5 # This software is subject to the provisions of the Zope Public License,
6 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
10 # FOR A PARTICULAR PURPOSE.
11 #
12 ##############################################################################
13 """ Common pieces of the workflow architecture.
15 $Id$
16 """
18 from warnings import warn
20 from Acquisition import aq_base
21 from MethodObject import Method
23 from utils import getToolByName
26 class WorkflowException( Exception ):
28 """ Exception while invoking workflow.
29 """
32 class ObjectDeleted( Exception ):
34 """ Raise to tell the workflow tool that the object has been deleted.
36 Swallowed by the workflow tool.
37 """
38 def __init__(self, result=None):
39 self._r = result
41 def getResult(self):
42 return self._r
45 class ObjectMoved( Exception ):
47 """ Raise to tell the workflow tool that the object has moved.
49 Swallowed by the workflow tool.
50 """
51 def __init__(self, new_ob, result=None):
52 self._ob = new_ob # Includes acquisition wrappers.
53 self._r = result
55 def getResult(self):
56 return self._r
58 def getNewObject(self):
59 return self._ob
62 class WorkflowMethod( Method ):
64 """ Wrap a method to workflow-enable it.
65 """
66 _need__name__=1
68 def __init__(self, method, id=None, reindex=1):
69 warn('WorkflowMethod() alias WorkflowAction() is deprecated and will '
70 'be removed in CMF 2.0.',
71 DeprecationWarning, stacklevel=2)
72 self._m = method
73 if id is None:
74 id = method.__name__
75 self._id = id
76 # reindex ignored since workflows now perform the reindexing.
78 def __call__(self, instance, *args, **kw):
80 """ Invoke the wrapped method, and deal with the results.
81 """
82 wf = getToolByName(instance, 'portal_workflow', None)
83 if wf is None or not hasattr(wf, 'wrapWorkflowMethod'):
84 # No workflow tool found.
85 try:
86 res = self._m(instance, *args, **kw)
87 except ObjectDeleted, ex:
88 res = ex.getResult()
89 else:
90 if hasattr(aq_base(instance), 'reindexObject'):
91 instance.reindexObject()
92 else:
93 res = wf.wrapWorkflowMethod(instance, self._id, self._m,
94 (instance,) + args, kw)
95 return res
97 # Backward compatibility.
98 WorkflowAction = WorkflowMethod