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

Worklist.py: improve cataloged variable matches and action box variables, but...

Worklist.py: improve cataloged variable matches and action box variables, but action box still crashed.
parent 24e7c2f6
...@@ -26,7 +26,8 @@ ...@@ -26,7 +26,8 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# #
############################################################################## ##############################################################################
import re
from zLOG import LOG, WARNING
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Acquisition import aq_inner from Acquisition import aq_inner
from Acquisition import aq_parent from Acquisition import aq_parent
...@@ -40,6 +41,8 @@ from Products.DCWorkflow.permissions import ManagePortal ...@@ -40,6 +41,8 @@ from Products.DCWorkflow.permissions import ManagePortal
from Persistence import PersistentMapping from Persistence import PersistentMapping
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
tales_re = re.compile(r'(\w+:)?(.*)')
class Worklist(XMLObject): class Worklist(XMLObject):
""" """
A ERP5 Worklist. A ERP5 Worklist.
...@@ -53,6 +56,11 @@ class Worklist(XMLObject): ...@@ -53,6 +56,11 @@ class Worklist(XMLObject):
description = '' description = ''
var_matches = None # Compared with catalog when set. var_matches = None # Compared with catalog when set.
### zwj: following 3 variables take place var_matches for this moment
matched_portal_type = ''
matched_validation_state = ''
matched_simulation_state = ''
actbox_name = '' actbox_name = ''
actbox_url = '' actbox_url = ''
actbox_icon = '' actbox_icon = ''
...@@ -73,10 +81,10 @@ class Worklist(XMLObject): ...@@ -73,10 +81,10 @@ class Worklist(XMLObject):
) )
def getGuard(self): def getGuard(self):
if self.guard is not None: if self.guard is None:
return self.guard self.generateGuard()
else: return self.guard ### only generate gurad when self is a User Action
return Guard().__of__(self) # Create a temporary guard. #return Guard().__of__(self) # Create a temporary guard.
def getGuardSummary(self): def getGuardSummary(self):
res = None res = None
...@@ -84,6 +92,24 @@ class Worklist(XMLObject): ...@@ -84,6 +92,24 @@ class Worklist(XMLObject):
res = self.guard.getSummary() res = self.guard.getSummary()
return res return res
def generateGuard(self):
if self.getRoleList() is not None or self.getGroupList() is not None:
if self.guard == None:
self.guard = Guard(permissions=self.getPermissionList(),
roles=self.getRoleList(),
groups=self.getGroupList(),
expr=self.getExpression())
if self.guard.roles != self.getRoleList():
self.guard.roles = self.getRoleList()
elif self.guard.permissions != self.getPermissionList():
self.guard.permissions = self.getPermissionList()
elif self.guard.groups != self.getGroupList():
self.guard.groups = self.getGroupList()
elif self.guard.expr != self.getExpression():
self.guard.expr = self.getExpression()
def getAvailableCatalogVars(self): def getAvailableCatalogVars(self):
res = [] res = []
res.append(self.getParentValue().getStateBaseCategory()) res.append(self.getParentValue().getStateBaseCategory())
...@@ -94,19 +120,42 @@ class Worklist(XMLObject): ...@@ -94,19 +120,42 @@ class Worklist(XMLObject):
res.sort() res.sort()
return res return res
### zwj: this function has been modified from original one
def getVarMatchKeys(self): def getVarMatchKeys(self):
if self.var_matches: key_list = []
return self.var_matches.keys() if self.getMatchedSimulationState() is not None:
else: key_list.append('portal_type')
return [] key_list.append('simulation_state')
if self.getMatchedValidationState() is not None:
key_list.append('portal_type')
key_list.append('validation_state')
if self.getMatchedSimulationState() is not None and self.getMatchedValidationState() is not None:
raise NotImplementedError(' Please only fill the field of the state variable defined in this workflow.')
return key_list
### zwj: this function has been modified from original one
def getVarMatch(self, id): def getVarMatch(self, id):
if self.var_matches: self.var_matches = {}
matches = self.var_matches.get(id, ()) matches = ''
if id == 'portal_type':
v = ''.join(self.getMatchedPortalTypeList())
LOG(' v is %s'%v, WARNING, 'in Worklist.py')
if tales_re.match(v).group(1):
matches = Expression(v)
else:
v = [ var.strip() for var in self.getMatchedPortalTypeList() ]
matches = tuple(v)
elif id == 'validation_state':
matches = tuple(self.getMatchedValidationState())
elif id == 'simulation_stae':
matches = tuple(Expression(self.getMatchedSimulationState()))
else:
raise NotImplementedError ("Cataloged variable matching error in Worklist.py")
if matches is not None:
if not isinstance(matches, (tuple, Expression)): if not isinstance(matches, (tuple, Expression)):
# Old version, convert it. # Old version, convert it.
matches = (matches,) matches = (matches,)
self.var_matches[id] = matches self.var_matches[id] = str(matches)
return matches return matches
else: else:
return () return ()
......
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