Commit a4e398c4 authored by wenjie.zheng's avatar wenjie.zheng

Worklist.py: make getVarMatchKey return sub-dynamic-variable reference to fix...

Worklist.py: make getVarMatchKey return sub-dynamic-variable reference to fix fmt_data wrong variable key error.
parent c419538b
......@@ -79,7 +79,7 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject):
def getGuard(self):
if self.guard is None:
self.generateGuard()
self.generateGuard()
return self.guard
def getGuardSummary(self):
......@@ -91,6 +91,7 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject):
def generateGuard(self):
if self.guard == None:
self.guard = Guard()
if self.getRoleList() is not None:
self.guard.roles = self.getRoleList()
if self.getPermissionList() is not None:
......@@ -106,6 +107,8 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject):
for vdef in self.getParentValue().contentValues(portal_type="Variable"):
if vdef.for_catalog:
res.append(vdef.getId())
for vdef in self.objectValues():
res.append(vdef.getId())
res.sort()
return res
......@@ -120,28 +123,27 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject):
def _updateDynamicVariable(self):
# Keep worklist variables updating, correspond to workflow variables.
# In the new workflow, we may not need this function for the moment.
res = []
workflow_variable_id_list = []
default_variable_id_list = ['variable_action', 'variable_actor',\
'variable_comment', 'variable_error_message', 'variable_history',\
'variable_portal_type', 'variable_time']
"""
This step serves as the for_catalog function in DC Workflow:
Whenever the for_catalog is 1 in workflow variable, we can configurate
the value of this variable in worklist's automatic created sub-variable.
But it may create too many sub object in worklist.
Check workflow variables:
"""
for variable_value in self.getParentValue().objectValues(portal_type="Variable"):
variable_id = variable_value.getId()
workflow_variable_id_list.append(variable_id)
worklist_variable_value = self._getOb(variable_id, None)
if worklist_variable_value is None and variable_value.for_catalog == 1:
if worklist_variable_value is None and variable_value.for_catalog == 1 and variable_id not in default_variable_id_list:
variable_value_ref = variable_value.getReference()
worklist_variable_value = self.newContent(portal_type='Worklist Variable')
worklist_variable_value.setReference(variable_value_ref)
worklist_variable_value.setDefaultExpr(variable_value.getDefaultExpr())
worklist_variable_value.setInitialValue(variable_value.getInitialValue())
res.append(worklist_variable_value)
elif worklist_variable_value not in res and variable_value.for_catalog == 1:
if worklist_variable_value and worklist_variable_value not in res and variable_value.for_catalog == 1:
res.append(worklist_variable_value)
if worklist_variable_value in res and variable_value.for_catalog == 0:
self._delObject(variable_id)
......@@ -153,6 +155,8 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject):
for worklist_variable_value in self.objectValues():
if worklist_variable_value.getId() not in workflow_variable_id_list:
res.append(worklist_variable_value)
workflow_variable_id_list.append(worklist_variable_value.getId())
LOG(" worklist '%s' has variable '%s'"%(self.getId(),workflow_variable_id_list ),0, " in Worklist.py 159")
return res
def getVarMatchKeys(self):
......@@ -166,7 +170,8 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject):
if self.getMatchedCausalityState() is not None:
key_list.append('causality_state')
for dynamic_variable in self.objectValues():
key_list.append(dynamic_variable.getId())
if dynamic_variable.getInitialValue() or dynamic_variable.getDefaultExpr():
key_list.append(dynamic_variable.getReference())
return key_list
def getVarMatch(self, id):
......@@ -175,30 +180,29 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject):
matches_ref_list = []
if id == 'portal_type':
v = self.getMatchedPortalTypeList()
if v is not None:
matches = tuple(v)
matches = tuple(v)
elif id in ['validation_state', 'simulation_state']:
if id == 'validation_state':
matches_id_list = self.getMatchedValidationStateList()
elif id == 'simulation_state':
matches_id_list = self.getMatchedSimulationStateList()
# Get workflow state's reference:
for state_id in matches_id_list:
if hasattr(self.getParent(), state_id):
matches_ref_list.append(self.getParent()._getOb(state_id).getReference())
matches = tuple(matches_ref_list)
elif id == 'causality_state':
matches_id = self.getMatchedCausalityState()
if matches_id is None:
matches_id = ''
matches_ref_list.append(matches_id)
matches = tuple(matches_ref_list)
else:
# local dynamic variable
matched_value = self._getOb(id).getInitialValue()
if self._getOb(id).getDefaultExpr() is not None:
matched_value = self._getOb(id).getDefaultExpr()
matches_ref_list.append(matched_value)
matches = tuple(matches_ref_list)
# Local dynamic variable:
dynamic_varible = self._getOb('variable_'+id)
if dynamic_varible.getInitialValue():
matches = dynamic_varible.getInitialValue()
# Override initial value if expression set:
if dynamic_varible.getDefaultExpr():
matches = Expression(dynamic_varible.getDefaultExpr())
if matches is not [] and matches is not None:
if not isinstance(matches, (tuple, Expression)):
......@@ -213,43 +217,3 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject):
if isinstance(values, Expression):
return values.text
return '; '.join(values)
def setProperties(self, description,
actbox_name='', actbox_url='', actbox_category='global',
actbox_icon='', props=None, REQUEST=None):
if props is None:
props = REQUEST
self.description = str(description)
LOG(" ***** props in worklist is '%s'"%props, 0, 0)
for k in self.getAvailableCatalogVars():
# in new worklist, use properties to set value.
v = props.get(k, '')
if v:
if k == 'guard_expr':
self.setExpression(v)
elif k == 'variable_portal_type':
self.setMatchedPortalTypeList(v)
elif k == 'variable_validation_state':
self.setMatchedValidationState('state_'+v)
elif k == 'variable_base_category_id':
self.setActboxCategory(v)
elif k == 'guard_roles':
r = [ var.strip() for var in v.split(';') ]
self.setRoleList(r)
# Add dynamic variable as worklist sub-object
elif k.startswith('variable_'):
# remove prefix from variable id;
variable_value_ref = '_'.join(k.split('_')[1:])
# Add a local worklist variable:
variable_value = self.newContent(portal_type='Worklist Variable')
variable_value.setReference(variable_value_ref)
if tales_re.match(v).group(1):
# Found a TALES prefix
variable_value.setDefaultExpr(v)
else:
variable_value.setInitialValue(v)
self.actbox_name = str(actbox_name)
self.actbox_url = str(actbox_url)
self.actbox_category = str(actbox_category)
self.actbox_icon = str(actbox_icon)
self.guard = self.getGuard()
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