Commit b009df74 authored by Vincent Pelletier's avatar Vincent Pelletier

(Partialy) Update comments and coding style.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@18555 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f5a732f7
...@@ -174,15 +174,13 @@ class XMLMatrix(Folder): ...@@ -174,15 +174,13 @@ class XMLMatrix(Folder):
'_setCellRange' ) '_setCellRange' )
def _setCellRange(self, *kw, **kwd): def _setCellRange(self, *kw, **kwd):
""" """
Set a new range for a matrix, this method can Set a new range for a matrix.
also handle a changement of the size of a matrix If needed, it will resize and/or reorder matrix content.
""" """
movement = {} # We will put in this dictionnary the previous and new movement = {} # Maps original cell id to its new id for each moved cell.
# id of a given cell new_index = PersistentMapping()
new_index = PersistentMapping() # new_index defines the relation
# between keys and ids of cells
base_id= kwd.get('base_id', "cell") base_id = kwd.get('base_id', 'cell')
if getattr(aq_base(self), 'index', None) is None: if getattr(aq_base(self), 'index', None) is None:
self.index = PersistentMapping() self.index = PersistentMapping()
...@@ -191,7 +189,7 @@ class XMLMatrix(Folder): ...@@ -191,7 +189,7 @@ class XMLMatrix(Folder):
if current_range == list(kw): # kw is a tuple if current_range == list(kw): # kw is a tuple
return return
# Recreate a new index for the new range defined in *kw # Create the new index for the range given in *kw
i = 0 i = 0
for index_ids in kw: for index_ids in kw:
temp = PersistentMapping() temp = PersistentMapping()
...@@ -203,25 +201,21 @@ class XMLMatrix(Folder): ...@@ -203,25 +201,21 @@ class XMLMatrix(Folder):
i += 1 i += 1
if self.index.has_key(base_id): if self.index.has_key(base_id):
# Look at each dimension i of the previous index # Compute cell movement from their position in previous range to their
# position in the new range.
for i, i_value in self.index[base_id].iteritems(): for i, i_value in self.index[base_id].iteritems():
# If the new index has the same dimensionality
# Look at new location of cells
if new_index.has_key(i): if new_index.has_key(i):
temp = {} temp = {}
# Look at each index in a given dimension i
for my_id, my_value in i_value.iteritems(): for my_id, my_value in i_value.iteritems():
# create a movement in dimension i between old_place and new_place
temp[my_value] = new_index[i].get(my_id) temp[my_value] = new_index[i].get(my_id)
movement[i] = temp movement[i] = temp
# Rename every 'object_id' by 'temp_object_id' # List all valid cell ids for current base_id.
object_id_list = [] object_id_list = []
for obj in self.objectValues(): for obj in self.objectValues():
object_id = obj.getId() object_id = obj.getId()
if object_id.find(base_id) == 0: if object_id.find(base_id) == 0:
# We want to make sure we have only base_id, ex: foo_0_0 and # Check that all '_'-separated fields are of int type.
# not foo_bar_0_0
if (object_id) > len(base_id): if (object_id) > len(base_id):
try: try:
int(object_id[len(base_id)+1:].split('_')[0]) int(object_id[len(base_id)+1:].split('_')[0])
...@@ -233,14 +227,16 @@ class XMLMatrix(Folder): ...@@ -233,14 +227,16 @@ class XMLMatrix(Folder):
except (ValueError, KeyError): except (ValueError, KeyError):
pass pass
# Prepend 'temp_' to all cells, to avoid id conflicts while renaming.
for object_id in object_id_list: for object_id in object_id_list:
new_name = 'temp_' + object_id new_name = 'temp_' + object_id
obj = self._getOb(object_id) obj = self._getOb(object_id)
obj.isIndexable = 0 # block reindexing at this time obj.isIndexable = 0 # Disable reindexing while moving cells
obj.id = new_name obj.id = new_name
self._setObject(new_name, aq_base(obj)) self._setObject(new_name, aq_base(obj))
self._delObject(object_id) self._delObject(object_id)
# Rename all cells to their final name.
for object_id in object_id_list: for object_id in object_id_list:
# Retrieve the place of the object, for movement_0_0 it is ['0','0'] # Retrieve the place of the object, for movement_0_0 it is ['0','0']
object_place = object_id[len(base_id)+1:].split('_') object_place = object_id[len(base_id)+1:].split('_')
......
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