Commit 0ad56e83 authored by Nicolas Dumazet's avatar Nicolas Dumazet

use a local addError() handler to avoid code duplication


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@32735 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 46391d12
...@@ -636,7 +636,17 @@ class XMLMatrix(Folder): ...@@ -636,7 +636,17 @@ class XMLMatrix(Folder):
""" """
# Check useless cells # Check useless cells
to_delete = [] to_delete = []
errors = [] error_list = []
def addError(message):
if fixit:
error_message += ' (fixed)'
error = (self.getRelativeUrl(),
'XMLMatrix inconsistency',
102,
error_message)
error_list.append(error)
# We make sure first that there is an index # We make sure first that there is an index
if getattr(aq_base(self), 'index', None) is None: if getattr(aq_base(self), 'index', None) is None:
self.index = PersistentMapping() self.index = PersistentMapping()
...@@ -668,19 +678,15 @@ class XMLMatrix(Folder): ...@@ -668,19 +678,15 @@ class XMLMatrix(Folder):
if test_num is not None: if test_num is not None:
if not self.index.has_key(base_id): if not self.index.has_key(base_id):
# The matrix does not have this base_id # The matrix does not have this base_id
error_message = "There is no index for base_id %s" % base_id addError("There is no index for base_id %s" % base_id)
if fixit: error_message += ' (fixed)'
errors += [(self.getRelativeUrl(), 'XMLMatrix inconsistency',102,error_message)]
if object_id not in to_delete: if object_id not in to_delete:
to_delete += [object_id] to_delete.append(object_id)
else: else:
# Check empty indices. # Check empty indices.
empty_list = [] empty_list = []
for i in self.index[base_id].keys(): for i in self.index[base_id].keys():
if self.index[base_id][i] is None or len(self.index[base_id][i]) == 0: if self.index[base_id][i] is None or len(self.index[base_id][i]) == 0:
error_message = "There is no id for the %dth axis of base_id %s" % (i, base_id) addError("There is no id for the %dth axis of base_id %s" % (i, base_id))
if fixit: error_message += ' (fixed)'
errors += [(self.getRelativeUrl(), 'XMLMatrix inconsistency',102,error_message)]
empty_list.append(i) empty_list.append(i)
if fixit: if fixit:
for i in empty_list: for i in empty_list:
...@@ -688,25 +694,21 @@ class XMLMatrix(Folder): ...@@ -688,25 +694,21 @@ class XMLMatrix(Folder):
len_id = len(self.index[base_id]) len_id = len(self.index[base_id])
if len(object_id_split) != (len_id + base_id_len): # +1 for the quantity if len(object_id_split) != (len_id + base_id_len): # +1 for the quantity
error_message = "Dimension of cell is %s but should be %s" % (len(object_id_split) addError("Dimension of cell is %s but should be %s" % (len(object_id_split)
- base_id_len, len_id) - base_id_len, len_id))
if fixit: error_message += ' (fixed)'
errors += [(self.getRelativeUrl(), 'XMLMatrix inconsistency',102,error_message)]
if object_id not in to_delete: if object_id not in to_delete:
to_delete += [object_id] to_delete.append(object_id)
else : else :
for i in range(len_id): for i in range(len_id):
if int(object_id_split[i+base_id_len]) >= len(self.index[base_id][i]): if int(object_id_split[i+base_id_len]) >= len(self.index[base_id][i]):
error_message = "Cell %s is out of bound" % object_id addError("Cell %s is out of bound" % object_id)
if fixit: error_message += ' (fixed)'
errors += [(self.getRelativeUrl(), 'XMLMatrix inconsistency',102,error_message)]
if object_id not in to_delete: if object_id not in to_delete:
to_delete += [object_id] to_delete.append(object_id)
if fixit and len(to_delete) > 0: if fixit and len(to_delete) > 0:
self.manage_delObjects(to_delete) self.manage_delObjects(to_delete)
return errors return error_list
security.declareProtected( Permissions.ModifyPortalContent, 'notifyAfterUpdateRelatedContent' ) security.declareProtected( Permissions.ModifyPortalContent, 'notifyAfterUpdateRelatedContent' )
def notifyAfterUpdateRelatedContent(self, previous_category_url, new_category_url): def notifyAfterUpdateRelatedContent(self, previous_category_url, new_category_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