Commit 9157b3cd authored by wenjie.zheng's avatar wenjie.zheng

Worklist.py: deploy worklist variable to support dynamic variable.

parent ad093324
...@@ -110,10 +110,29 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject): ...@@ -110,10 +110,29 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject):
return res return res
def updateDynamicVariable(self): def updateDynamicVariable(self):
# keep worklist variables updating, correspond to workflow variables. # Keep worklist variables updating, correspond to workflow variables.
# In the new workflow, we may not need this function for the moment.
res = [] res = []
for worklist_variable_value in self.objectValues():
res.append(worklist_variable_value)
return res
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 = []
"""
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.
"""
for variable_value in self.getParentValue().objectValues(portal_type="Variable"): for variable_value in self.getParentValue().objectValues(portal_type="Variable"):
variable_id = variable_value.getId() variable_id = variable_value.getId()
workflow_variable_id_list.append(variable_id)
worklist_variable_value = self._getOb(variable_id, None) 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:
variable_value_ref = variable_value.getReference() variable_value_ref = variable_value.getReference()
...@@ -125,9 +144,15 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject): ...@@ -125,9 +144,15 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject):
elif worklist_variable_value not in res and variable_value.for_catalog == 1: elif worklist_variable_value not in res and variable_value.for_catalog == 1:
res.append(worklist_variable_value) res.append(worklist_variable_value)
if worklist_variable_value in res and variable_value.for_catalog == 0: if worklist_variable_value in res and variable_value.for_catalog == 0:
res.remove(worklist_variable_value)
self._delObject(variable_id) self._delObject(variable_id)
res.remove(worklist_variable_value)
"""
Append user created worklist variables.
"""
for worklist_variable_value in self.objectValues():
if worklist_variable_value.getId() not in workflow_variable_id_list:
res.append(worklist_variable_value)
return res return res
def getVarMatchKeys(self): def getVarMatchKeys(self):
...@@ -140,6 +165,8 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject): ...@@ -140,6 +165,8 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject):
key_list.append('validation_state') key_list.append('validation_state')
if self.getMatchedCausalityState() is not None: if self.getMatchedCausalityState() is not None:
key_list.append('causality_state') key_list.append('causality_state')
for dynamic_variable in self.objectValues():
key_list.append(dynamic_variable.getId())
return key_list return key_list
def getVarMatch(self, id): def getVarMatch(self, id):
...@@ -150,7 +177,7 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject): ...@@ -150,7 +177,7 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject):
v = self.getMatchedPortalTypeList() v = self.getMatchedPortalTypeList()
if v is not None: if v is not None:
matches = tuple(v) matches = tuple(v)
if id in ['validation_state', 'simulation_state']: elif id in ['validation_state', 'simulation_state']:
if id == 'validation_state': if id == 'validation_state':
matches_id_list = self.getMatchedValidationStateList() matches_id_list = self.getMatchedValidationStateList()
elif id == 'simulation_state': elif id == 'simulation_state':
...@@ -159,12 +186,19 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject): ...@@ -159,12 +186,19 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject):
if hasattr(self.getParent(), state_id): if hasattr(self.getParent(), state_id):
matches_ref_list.append(self.getParent()._getOb(state_id).getReference()) matches_ref_list.append(self.getParent()._getOb(state_id).getReference())
matches = tuple(matches_ref_list) matches = tuple(matches_ref_list)
if id == 'causality_state': elif id == 'causality_state':
matches_id = self.getMatchedCausalityState() matches_id = self.getMatchedCausalityState()
if matches_id is None: if matches_id is None:
matches_id = '' matches_id = ''
matches_ref_list.append(matches_id) matches_ref_list.append(matches_id)
matches = tuple(matches_ref_list) 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)
if matches is not [] and matches is not None: if matches is not [] and matches is not None:
if not isinstance(matches, (tuple, Expression)): if not isinstance(matches, (tuple, Expression)):
...@@ -202,24 +236,20 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject): ...@@ -202,24 +236,20 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject):
elif k == 'guard_roles': elif k == 'guard_roles':
r = [ var.strip() for var in v.split(';') ] r = [ var.strip() for var in v.split(';') ]
self.setRoleList(r) self.setRoleList(r)
# Add dynamic variable as worklist sub-object
elif k.startswith('variable_'): elif k.startswith('variable_'):
# remove prefix from variable id; # remove prefix from variable id;
worklist_variable_value_ref = '_'.join(k.split('_')[1:]) variable_value_ref = '_'.join(k.split('_')[1:])
worklist_variable_value = self.newContent(id=k, portal_type='Worklist Variable') # Add a local worklist variable:
worklist_variable_value.setReference(k) variable_value = self.newContent(portal_type='Worklist Variable')
LOG(" add worklist variable '%s' to support dynamic variable"%worklist_variable_value.getId(),0," in Worklist.py") variable_value.setReference(variable_value_ref)
if tales_re.match(v).group(1): if tales_re.match(v).group(1):
# Found a TALES prefix # Found a TALES prefix
worklist_variable_value.setDefaultExpr(v) variable_value.setDefaultExpr(v)
else: else:
worklist_variable_value.setInitialValue(v) variable_value.setInitialValue(v)
self.actbox_name = str(actbox_name) self.actbox_name = str(actbox_name)
self.actbox_url = str(actbox_url) self.actbox_url = str(actbox_url)
self.actbox_category = str(actbox_category) self.actbox_category = str(actbox_category)
self.actbox_icon = str(actbox_icon) self.actbox_icon = str(actbox_icon)
g = Guard() self.guard = self.getGuard()
if g.changeFromProperties(props or REQUEST):
self.guard = g
else:
self.guard = 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