vendor/CMF/1.6.1/DCWorkflow

view Transitions.py @ 0:238bab7e7116

CMF 1.6.1 vendor import
author fguillaume
date Tue, 13 Jun 2006 14:57:59 +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 """ Transitions in a web-configurable workflow.
15 $Id: Transitions.py 36457 2004-08-12 15:07:44Z jens $
16 """
18 from OFS.SimpleItem import SimpleItem
19 from Globals import DTMLFile
20 from Globals import PersistentMapping
21 from Globals import InitializeClass
22 from Acquisition import aq_inner
23 from Acquisition import aq_parent
24 from AccessControl import ClassSecurityInfo
26 from ContainerTab import ContainerTab
27 from Guard import Guard
28 from permissions import ManagePortal
29 from utils import _dtmldir
30 from Expression import Expression
32 TRIGGER_AUTOMATIC = 0
33 TRIGGER_USER_ACTION = 1
34 TRIGGER_WORKFLOW_METHOD = 2
37 class TransitionDefinition (SimpleItem):
38 """Transition definition"""
40 meta_type = 'Workflow Transition'
42 security = ClassSecurityInfo()
43 security.declareObjectProtected(ManagePortal)
45 title = ''
46 description = ''
47 new_state_id = ''
48 trigger_type = TRIGGER_USER_ACTION
49 guard = None
50 actbox_name = ''
51 actbox_url = ''
52 actbox_category = 'workflow'
53 var_exprs = None # A mapping.
54 script_name = None # Executed before transition
55 after_script_name = None # Executed after transition
57 manage_options = (
58 {'label': 'Properties', 'action': 'manage_properties'},
59 {'label': 'Variables', 'action': 'manage_variables'},
60 )
62 def __init__(self, id):
63 self.id = id
65 def getId(self):
66 return self.id
68 def getGuardSummary(self):
69 res = None
70 if self.guard is not None:
71 res = self.guard.getSummary()
72 return res
74 def getGuard(self):
75 if self.guard is not None:
76 return self.guard
77 else:
78 return Guard().__of__(self) # Create a temporary guard.
80 def getVarExprText(self, id):
81 if not self.var_exprs:
82 return ''
83 else:
84 expr = self.var_exprs.get(id, None)
85 if expr is not None:
86 return expr.text
87 else:
88 return ''
90 def getWorkflow(self):
91 return aq_parent(aq_inner(aq_parent(aq_inner(self))))
93 def getAvailableStateIds(self):
94 return self.getWorkflow().states.keys()
96 def getAvailableScriptIds(self):
97 return self.getWorkflow().scripts.keys()
99 def getAvailableVarIds(self):
100 return self.getWorkflow().variables.keys()
102 _properties_form = DTMLFile('transition_properties', _dtmldir)
104 def manage_properties(self, REQUEST, manage_tabs_message=None):
105 '''
106 '''
107 return self._properties_form(REQUEST,
108 management_view='Properties',
109 manage_tabs_message=manage_tabs_message,
110 )
112 def setProperties(self, title, new_state_id,
113 trigger_type=TRIGGER_USER_ACTION, script_name='',
114 after_script_name='',
115 actbox_name='', actbox_url='',
116 actbox_category='workflow',
117 props=None, REQUEST=None, description=''):
118 '''
119 '''
120 self.title = str(title)
121 self.description = str(description)
122 self.new_state_id = str(new_state_id)
123 self.trigger_type = int(trigger_type)
124 self.script_name = str(script_name)
125 self.after_script_name = str(after_script_name)
126 g = Guard()
127 if g.changeFromProperties(props or REQUEST):
128 self.guard = g
129 else:
130 self.guard = None
131 self.actbox_name = str(actbox_name)
132 self.actbox_url = str(actbox_url)
133 self.actbox_category = str(actbox_category)
134 if REQUEST is not None:
135 return self.manage_properties(REQUEST, 'Properties changed.')
137 _variables_form = DTMLFile('transition_variables', _dtmldir)
139 def manage_variables(self, REQUEST, manage_tabs_message=None):
140 '''
141 '''
142 return self._variables_form(REQUEST,
143 management_view='Variables',
144 manage_tabs_message=manage_tabs_message,
145 )
147 def getVariableExprs(self):
148 ''' get variable exprs for management UI
149 '''
150 ve = self.var_exprs
151 if ve is None:
152 return []
153 else:
154 ret = []
155 for key in ve.keys():
156 ret.append((key,self.getVarExprText(key)))
157 return ret
159 def getWorkflowVariables(self):
160 ''' get all variables that are available form
161 workflow and not handled yet.
162 '''
163 wf_vars = self.getAvailableVarIds()
164 if self.var_exprs is None:
165 return wf_vars
166 ret = []
167 for vid in wf_vars:
168 if not self.var_exprs.has_key(vid):
169 ret.append(vid)
170 return ret
172 def addVariable(self, id, text, REQUEST=None):
173 '''
174 Add a variable expression.
175 '''
176 if self.var_exprs is None:
177 self.var_exprs = PersistentMapping()
179 expr = None
180 if text:
181 expr = Expression(str(text))
182 self.var_exprs[id] = expr
184 if REQUEST is not None:
185 return self.manage_variables(REQUEST, 'Variable added.')
187 def deleteVariables(self,ids=[],REQUEST=None):
188 ''' delete a WorkflowVariable from State
189 '''
190 ve = self.var_exprs
191 for id in ids:
192 if ve.has_key(id):
193 del ve[id]
195 if REQUEST is not None:
196 return self.manage_variables(REQUEST, 'Variables deleted.')
198 def setVariables(self, ids=[], REQUEST=None):
199 ''' set values for Variables set by this state
200 '''
201 if self.var_exprs is None:
202 self.var_exprs = PersistentMapping()
204 ve = self.var_exprs
206 if REQUEST is not None:
207 for id in ve.keys():
208 fname = 'varexpr_%s' % id
210 val = REQUEST[fname]
211 expr = None
212 if val:
213 expr = Expression(str(REQUEST[fname]))
214 ve[id] = expr
216 return self.manage_variables(REQUEST, 'Variables changed.')
218 InitializeClass(TransitionDefinition)
221 class Transitions (ContainerTab):
222 """A container for transition definitions"""
224 meta_type = 'Workflow Transitions'
226 security = ClassSecurityInfo()
227 security.declareObjectProtected(ManagePortal)
229 all_meta_types = ({'name':TransitionDefinition.meta_type,
230 'action':'addTransition',
231 },)
233 _manage_transitions = DTMLFile('transitions', _dtmldir)
235 def manage_main(self, REQUEST, manage_tabs_message=None):
236 '''
237 '''
238 return self._manage_transitions(
239 REQUEST,
240 management_view='Transitions',
241 manage_tabs_message=manage_tabs_message,
242 )
244 def addTransition(self, id, REQUEST=None):
245 '''
246 '''
247 tdef = TransitionDefinition(id)
248 self._setObject(id, tdef)
249 if REQUEST is not None:
250 return self.manage_main(REQUEST, 'Transition added.')
252 def deleteTransitions(self, ids, REQUEST=None):
253 '''
254 '''
255 for id in ids:
256 self._delObject(id)
257 if REQUEST is not None:
258 return self.manage_main(REQUEST, 'Transition(s) removed.')
260 InitializeClass(Transitions)