Commit d5cc61e1 authored by iv's avatar iv

ERP5Workflow: move methods from State to PermissionRoles class

because they are related to the cells
parent 1e0b59d4
...@@ -83,6 +83,27 @@ class PermissionRoles(XMLObject): ...@@ -83,6 +83,27 @@ class PermissionRoles(XMLObject):
def _getRoleIndex(self): def _getRoleIndex(self):
return int(self.id[len(self.base_id+'_'):].split('_')[1]) return int(self.id[len(self.base_id+'_'):].split('_')[1])
def _getPermissionOrRole(self, is_role=False):
# 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_prefix][index] = {'Some Role Or Permission': 1,
# 'Some Other One': 0, ...}
if is_role:
cell_permission_or_role_index = self._getRoleIndex()
else:
cell_permission_or_role_index = self._getPermissionIndex()
index = int(is_role)
for key, value in self.index[self.base_id][index].items():
if cell_permission_or_role_index == value:
return key
raise ValueError('No key found for value %s.' % value)
def _getPermission(self):
return self._getPermissionOrRole(is_role=False)
def _getRole(self):
return self._getPermissionOrRole(is_role=True)
def _setSelected(self, value): def _setSelected(self, value):
""" """
edit the parent state's permission/role dict to reflect current cell selection (selected) status edit the parent state's permission/role dict to reflect current cell selection (selected) status
......
...@@ -118,32 +118,10 @@ class State(IdAsReferenceMixin("state_", "prefix"), XMLObject, CustomStorageMatr ...@@ -118,32 +118,10 @@ class State(IdAsReferenceMixin("state_", "prefix"), XMLObject, CustomStorageMatr
'current_inventory', 'current_inventory',
) )
# move next 3 methods to PermissionRoles.py
def _getCellPermissionOrRole(self, cell, is_role):
# 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_prefix][index] = {'Some Role Or Permission': 1,
# 'Some Other One': 0, ...}
if is_role:
cell_permission_or_role_index = cell._getRoleIndex()
else:
cell_permission_or_role_index = cell._getPermissionIndex()
index = int(is_role)
for key, value in self.index[cell.base_id][index].items():
if cell_permission_or_role_index == value:
return key
raise ValueError('No key found for value %s.' % value)
def _getCellPermission(self, cell):
return self._getCellPermissionOrRole(cell, False)
def _getCellRole(self, cell):
return self._getCellPermissionOrRole(cell, True)
def updateCellFromCustomStorage(self, cell, **kw): def updateCellFromCustomStorage(self, cell, **kw):
""" """
Creates a new content as a matrix box cell. Creates a new content as a matrix box cell.
""" """
cell_permission = self._getCellPermission(cell) cell_permission = cell._getPermission()
cell_role = self._getCellRole(cell) cell_role = cell._getRole()
cell.selected = cell_role in self.state_permission_roles[cell_permission] cell.selected = cell_role in self.state_permission_roles[cell_permission]
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