Commit 3221daf3 authored by wenjie.zheng's avatar wenjie.zheng

Workflow.py: deploy property accessors as many as possible.

parent 775bab2d
......@@ -166,7 +166,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
return 0
if (transition in sdef.getDestinationValueList() and
self._checkTransitionGuard(transition, document) and
transition.trigger_type == TRIGGER_WORKFLOW_METHOD
transition.getTriggerType() == TRIGGER_WORKFLOW_METHOD
):
return 1
return 0
......@@ -184,7 +184,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
if action in sdef.getDestinationIdList():
tdef = self._getOb(action, None)
if (tdef is not None and
tdef.trigger_type == TRIGGER_USER_ACTION and
tdef.getTriggerType() == TRIGGER_USER_ACTION and
self._checkTransitionGuard(tdef, document, **kw)):
return 1
return 0
......@@ -212,7 +212,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
def _findAutomaticTransition(self, document, sdef):
tdef = None
for t in sdef.getDestinationValueList():
if t.trigger_type == TRIGGER_AUTOMATIC:
if t.getTriggerType() == TRIGGER_AUTOMATIC:
if self._checkTransitionGuard(t, document):
tdef = t
break
......@@ -268,7 +268,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
if tdef not in self.objectValues(portal_type='Transition'):
raise Unauthorized(action)
if tdef is None or tdef.trigger_type != TRIGGER_USER_ACTION:
if tdef is None or tdef.getTriggerType() != TRIGGER_USER_ACTION:
msg = _(u"Transition '${action_id}' is not triggered by a user "
u"action.", mapping={'action_id': action})
raise WorkflowException(msg)
......@@ -311,19 +311,19 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
for tid in sdef.getDestinationIdList():
tdef = self._getOb(id=tid)
if tdef is not None and tdef.trigger_type == TRIGGER_USER_ACTION and \
tdef.actbox_name and self._checkTransitionGuard(tdef, document):
if tdef is not None and tdef.getTriggerType() == TRIGGER_USER_ACTION and \
tdef.getActboxName() and self._checkTransitionGuard(tdef, document):
if fmt_data is None:
fmt_data = TemplateDict()
fmt_data._push(info)
fmt_data._push({'transition_id': tdef.getReference()})
res.append((tid, {
'id': tdef.getReference(),
'name': tdef.actbox_name % fmt_data,
'url': str(tdef.actbox_url) % fmt_data,
'icon': str(tdef.actbox_icon) % fmt_data,
'name': tdef.getActboxName() % fmt_data,
'url': str(tdef.getActboxUrl()) % fmt_data,
'icon': str(tdef.getActboxIcon()) % fmt_data,
'permissions': (), # Predetermined.
'category': tdef.actbox_category,
'category': tdef.getActboxCategory(),
'transition': tdef}))
fmt_data._pop()
res.sort()
......@@ -429,15 +429,16 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
getSecurityManager(), self, ob):
return default
status = self.getCurrentStatusDict(ob)
default_expr = vdef.getDefaultExpr()
if status is not None and status.has_key(name):
value = status[name]
# Not set yet. Use a default.
elif vdef.default_expr is not None:
elif default_expr is not None:
ec = createExprContext(StateChangeInfo(ob, self, status))
value = Expression(vdef.default_expr)(ec)
value = Expression(default_expr)(ec)
else:
value = vdef.default_value
value = vdef.getInitialValue()
return value
......@@ -462,7 +463,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
return status.copy()
def _getWorkflowStateOf(self, ob, id_only=0):
tool = getToolByName(self, 'portal_workflow')
tool = self.getParent()
id_no_suffix = self.getReference()
status = tool.getStatusOf(id_no_suffix, ob)
if status is None:
......@@ -547,7 +548,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
if prefix_method_id not in sdef.getDestinationIdList():
raise Unauthorized(method_id)
tdef = self._getOb(prefix_method_id)
if tdef is None or tdef.trigger_type != TRIGGER_WORKFLOW_METHOD:
if tdef is None or tdef.getTriggerType() != TRIGGER_WORKFLOW_METHOD:
raise WorkflowException, (
'Transition %s is not triggered by a workflow method'
% method_id)
......@@ -656,14 +657,14 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
for vdef in self.objectValues(portal_type='Variable'):
id = vdef.getId()
variable_reference = vdef.getReference()
if not vdef.for_status or vdef.for_status == 0:
if not vdef.getForStatus() or vdef.getForStatus() == 0:
continue
expr = None
if variable_reference in state_values:
value = state_values[variable_reference]
elif id in tdef_exprs:
expr = tdef_exprs[id]
elif not vdef.update_always and variable_reference in former_status:
elif not vdef.getAutomaticUpdate() and variable_reference in former_status:
# Preserve former value
value = former_status[variable_reference]
else:
......@@ -716,7 +717,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
if script:
# Script can be either script or workflow method
if script_id in old_sdef.getDestinationIdList() and \
self._getOb(script_id).trigger_type == TRIGGER_WORKFLOW_METHOD:
self._getOb(script_id).getTriggerType() == TRIGGER_WORKFLOW_METHOD:
getattr(document, convertToMixedCase(self._getOb(script_id).getReference()))()
else:
# Pass lots of info to the script in a single parameter.
......@@ -741,7 +742,7 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
if method_id not in sdef.getTransitionIdList():
raise Unauthorized(method_id)
tdef = self.getTransitionValueList().get(method_id, None)
if tdef is None or tdef.trigger_type != TRIGGER_WORKFLOW_METHOD:
if tdef is None or tdef.getTriggerType() != TRIGGER_WORKFLOW_METHOD:
raise WorkflowException, (
'Transition %s is not triggered by a workflow method'
% method_id)
......@@ -1056,21 +1057,22 @@ class Workflow(IdAsReferenceMixin("", "prefix"), XMLObject):
tdef_exprs = {}
status = {}
for id, vdef in self.getVariableValueList().items():
if vdef.for_status == 0:
if vdef.getForStatus() == 0:
continue
expr = None
if state_values.has_key(id):
value = state_values[id]
elif tdef_exprs.has_key(id):
expr = tdef_exprs[id]
elif not vdef.update_always and former_status.has_key(id):
elif not vdef.getAutomaticUpdate() and former_status.has_key(id):
# Preserve former value
value = former_status[id]
else:
if vdef.default_expr is not None:
expr = Expression(vdef.default_expr)
default_expr = vdef.getDefaultExpr()
if default_expr is not None:
expr = Expression(default_expr)
else:
value = vdef.default_value
value = vdef.getInitialValue()
if expr is not None:
# Evaluate an expression.
if econtext is None:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment