Commit ced674e1 authored by iv's avatar iv

ERP5Workflow: override newCellContent on the state matrix to use temporary objects

this avoid to create a big amount of objects for each state of each workflow
parent b092656b
......@@ -50,7 +50,6 @@ class State(IdAsReferenceMixin("state_", "prefix"), XMLObject, XMLMatrix):
add_permission = Permissions.AddPortalContent
isPortalContent = 1
isRADContent = 1
erp5_permission_roles = {} # { permission: [role] or (role,) }
default_reference = ''
state_type = ()
# Declarative security
......@@ -80,17 +79,10 @@ class State(IdAsReferenceMixin("state_", "prefix"), XMLObject, XMLMatrix):
def setPermission(self, permission, acquired, roles, REQUEST=None):
"""Set a permission for this State."""
permission_role = self.erp5_permission_roles
if permission_role is None:
self.erp5_permission_roles = permission_role = PersistentMapping()
if acquired:
roles = list(roles)
self.state_permission_roles[permission] = list(roles)
else:
roles = tuple(roles)
permission_role[permission] = roles
def getPermissionRoleList(self):
return self.erp5_permission_roles
self.state_permission_roles[permission] = tuple(roles)
def getDestinationReferenceList(self):
ref_list = []
......@@ -99,7 +91,8 @@ class State(IdAsReferenceMixin("state_", "prefix"), XMLObject, XMLMatrix):
return ref_list
def getAvailableTypeList(self):
"""This is a method specific to ERP5. This returns a list of state types, which are used for portal methods.
"""
This is a method specific to ERP5. This returns a list of state types, which are used for portal methods.
"""
return (
'draft_order',
......@@ -109,3 +102,40 @@ class State(IdAsReferenceMixin("state_", "prefix"), XMLObject, XMLMatrix):
'transit_inventory',
'current_inventory',
)
def _getPermissionOrRoleFromInfo(self, cell_prefix, cell_permission_or_role_index, index):
# we want to get the permission or role from its index,
# so we want the retrieve the key of the dict which is like:
# self.index[cell_info['prefix']][index] = {'Some Role Or Permission': 1}
for key, value in self.index[cell_prefix][index].items():
if cell_permission_or_role_index == value:
return key
return None
def getPermissionFromInfo(self, cell_info):
return self._getPermissionOrRoleFromInfo(
cell_info['prefix'],
cell_info['permission_index'],
0
)
def getRoleFromInfo(self, cell_info):
return self._getPermissionOrRoleFromInfo(
cell_info['prefix'],
cell_info['role_index'],
1
)
def newCellContent(self, cell_id, **kw):
"""
Creates a new content as a matrix box cell.
"""
cell = self.newContent(id=cell_id, temp_object=True, **kw)
cell_info = cell.getCellInfo()
cell_permission = self.getPermissionFromInfo(cell_info)
cell_role = self.getRoleFromInfo(cell_info)
is_selected = cell_role in self.state_permission_roles[cell_permission]
cell.setIsSelected(is_selected)
return cell
\ No newline at end of file
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