[Zope-CMF] DCWorkflow Question
Ulrich Eck
ueck@net-labs.de
Fri, 24 Aug 2001 14:46:00 +0200
Hi Shane,
I dived deep into DCWorkflow .. and the more I use it, the more i like it :))
after all source reading i have one question:
How can I modify Workflow-Variables from a Script that is executed through a
Transition ????
I have some Workflow-Variables defined, that are mapped to the Namespace
of the Script that I assigned for the Transistion, but they are read-only
(NamespaceAccessor doesn't allow updates)
I cannot assign any workflow-relevant vars except "new_state" ..
do you have a hint, how to get around this ??
I want to set a WorkflowVariable depending on the transistion that is
actually made.
thanks for your help
Ulrich Eck
net-labs
here the interesting source-part:
---------------------------------------------------------
DCWorkflow.py
...
def _executeTransition(self, ob, tdef=None, kwargs=None):
'''
Private method.
Puts object in a new state.
'''
moved = 0
if tdef is None:
state = self.initial_state
former_status = {}
action = ''
else:
state = tdef.new_state_id
if not state:
# Stay in same state.
state = self._getWorkflowStateOf(ob, 1)
former_status = self._getStatusOf(ob)
action = tdef.id
# Execute a script if specified.
if tdef.script_name:
script = self.scripts[tdef.script_name]
# Pass lots of info to the script in a single parameter.
######## Definition of the Namespace for the script
md = exprNamespace(ob, self, former_status,
action, state, kwargs)
accessor = NamespaceAccessor(md)
try:
######### HERE THE SCRIPT gets executed with exprNamespace (see lines above)
script(accessor) # May throw an exception.
except ObjectMoved, ex:
ob = ex.getNewObject()
moved = 1
sdef = self.states.get(state, None)
if sdef is None:
raise WorkflowException, 'Destination state undefined: ' + state
# Update variables.
state_values = sdef.var_values
if state_values is None: state_values = {}
tdef_exprs = None
if tdef is not None: tdef_exprs = tdef.var_exprs
if tdef_exprs is None: tdef_exprs = {}
status = {}
####### Here the variables get calculated
for id, vdef in self.variables.items():
if not vdef.for_status:
continue
if state_values.has_key(id):
value = state_values[id]
elif tdef_exprs.has_key(id):
md = exprNamespace(ob, self, former_status,
action, state, kwargs)
value = tdef_exprs[id](md)
elif vdef.default_expr is not None:
md = exprNamespace(ob, self, former_status,
action, state, kwargs)
value = vdef.default_expr(md)
else:
value = vdef.default_value
status[id] = value
# Update state.
status[self.state_var] = state
tool = aq_parent(aq_inner(self))
tool.setStatusOf(self.id, ob, status)
# Update role to permission assignments.
self.updateRoleMappingsFor(ob)
if moved:
# Re-raise.
raise ObjectMoved(ob)
else:
return sdef
----------------------------------------------------------------