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