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

Worklist.py: add dynamic variable updating function, the worklist variable now...

Worklist.py: add dynamic variable updating function, the worklist variable now keep updating correspond to workflow variable for_catalog setting.
parent ff11e41b
...@@ -44,6 +44,9 @@ tales_re = re.compile(r'(\w+:)?(.*)') ...@@ -44,6 +44,9 @@ tales_re = re.compile(r'(\w+:)?(.*)')
class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject): class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject):
""" """
A ERP5 Worklist. A ERP5 Worklist.
Four Variable: portal_type; simulation_state; validation_state; causality_state
can be accessed directly; other dynamic variables will be accessable through
content type "Worklist Variable".
""" """
meta_type = 'ERP5 Worklist' meta_type = 'ERP5 Worklist'
...@@ -52,7 +55,7 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject): ...@@ -52,7 +55,7 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject):
isPortalContent = 1 isPortalContent = 1
isRADContent = 1 isRADContent = 1
description = '' description = ''
var_matches = None # Compared with catalog when set. var_matches = [] # Compared with catalog when set.
matched_portal_type = '' matched_portal_type = ''
actbox_name = '' actbox_name = ''
actbox_url = '' actbox_url = ''
...@@ -101,12 +104,27 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject): ...@@ -101,12 +104,27 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject):
res = [] res = []
res.append(self.getParentValue().getStateVariable()) res.append(self.getParentValue().getStateVariable())
for vdef in self.getParentValue().contentValues(portal_type="Variable"): for vdef in self.getParentValue().contentValues(portal_type="Variable"):
id = vdef.getReference()
if vdef.for_catalog: if vdef.for_catalog:
res.append(id) res.append(vdef.getId())
res.sort() res.sort()
return res return res
def updateDynamicVariable(self):
# keep worklist variables updating, correspond to workflow variables.
for variable_value in self.getParentValue().objectValues(portal_type="Variable"):
variable_id = variable_value.getId()
worklist_variable_value = self._getOb(variable_id, None)
if worklist_variable_value is None and variable_value.for_catalog == 1:
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())
self.var_matches.append(worklist_variable_value)
elif worklist_variable_value in self.var_matches and variable_value.for_catalog == 0:
self.var_matches.remove(worklist_variable_value)
return self.var_matches
def getVarMatchKeys(self): def getVarMatchKeys(self):
key_list = [] key_list = []
if self.getMatchedPortalType() is not None: if self.getMatchedPortalType() is not None:
...@@ -165,7 +183,7 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject): ...@@ -165,7 +183,7 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject):
props = REQUEST props = REQUEST
self.description = str(description) self.description = str(description)
LOG(" ***** props in worklist is '%s'"%props, 0, 0) LOG(" ***** props in worklist is '%s'"%props, 0, 0)
for k in props: for k in self.getAvailableCatalogVars():
# in new worklist, use properties to set value. # in new worklist, use properties to set value.
v = props.get(k, '') v = props.get(k, '')
if v: if v:
...@@ -180,8 +198,17 @@ class Worklist(IdAsReferenceMixin("worklist_", "prefix"), XMLObject): ...@@ -180,8 +198,17 @@ 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)
else: elif k.startswith('variable_'):
LOG(" dynamic variable is not supported yet.",0," Worklist.py") # remove prefix from variable id;
worklist_variable_value_ref = '_'.join(k.split('_')[1:])
worklist_variable_value = self.newContent(id=k, portal_type='Worklist Variable')
worklist_variable_value.setReference(k)
LOG(" add worklist variable '%s' to support dynamic variable"%worklist_variable_value.getId(),0," in Worklist.py")
if tales_re.match(v).group(1):
# Found a TALES prefix
worklist_variable_value.setDefaultExpr(v)
else:
worklist_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)
......
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