[Erp5-report] r34873 kazuhiko - in /erp5/trunk/products/ERP5Type: ./ Core/ interfaces/
nobody at svn.erp5.org
nobody at svn.erp5.org
Fri Apr 30 10:09:55 CEST 2010
Author: kazuhiko
Date: Fri Apr 30 10:09:52 2010
New Revision: 34873
URL: http://svn.erp5.org?rev=34873&view=rev
Log:
* extend checkConsistency and fixConsistency API to accept 'filter' argument, that supports 'id' only for now.
* use boolean instead of 0/1 for fixit argument.
Modified:
erp5/trunk/products/ERP5Type/Base.py
erp5/trunk/products/ERP5Type/Core/Folder.py
erp5/trunk/products/ERP5Type/interfaces/constraint.py
Modified: erp5/trunk/products/ERP5Type/Base.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Base.py?rev=34873&r1=34872&r2=34873&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Base.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Base.py [utf8] Fri Apr 30 10:09:52 2010
@@ -2695,7 +2695,7 @@
# return self._recursiveApply(f)
# Content consistency implementation
- def _checkConsistency(self, fixit=0):
+ def _checkConsistency(self, fixit=False):
"""
Check the constitency of objects.
@@ -2709,10 +2709,10 @@
Private method.
"""
- return self._checkConsistency(fixit=1)
+ return self._checkConsistency(fixit=True)
security.declareProtected(Permissions.AccessContentsInformation, 'checkConsistency')
- def checkConsistency(self, fixit=0):
+ def checkConsistency(self, fixit=False, filter=None, **kw):
"""
Check the constitency of objects.
@@ -2739,19 +2739,19 @@
# We are looking inside all instances in constraints, then we check
# the consistency for all of them
- for constraint_instance in self.constraints:
+ for constraint_instance in self._filteredConstraintList(filter):
if fixit:
error_list2 = UnrestrictedMethod(
- constraint_instance.fixConsistency)(self)
+ constraint_instance.fixConsistency)(self, **kw)
else:
error_list2 = UnrestrictedMethod(
- constraint_instance.checkConsistency)(self)
+ constraint_instance.checkConsistency)(self, **kw)
if len(error_list2) > 0:
try:
if fixit:
- constraint_instance.fixConsistency(self)
+ constraint_instance.fixConsistency(self, **kw)
else:
- constraint_instance.checkConsistency(self)
+ constraint_instance.checkConsistency(self, **kw)
except Unauthorized:
error_list.append(getUnauthorizedErrorMessage(constraint_instance))
else:
@@ -2763,11 +2763,24 @@
return error_list
security.declareProtected(Permissions.ManagePortal, 'fixConsistency')
- def fixConsistency(self):
+ def fixConsistency(self, filter=None, **kw):
"""
Fix the constitency of objects.
"""
- return self.checkConsistency(fixit=1)
+ return self.checkConsistency(fixit=True, filter=filter, **kw)
+
+ def _filteredConstraintList(self, filt):
+ """
+ Returns a list of constraints filtered by filt argument.
+ """
+ # currently only 'id' is supported.
+ constraints = self.constraints
+ if filt is not None:
+ id_list = filt.get('id', None)
+ if isinstance(id_list, (list, tuple)):
+ id_list = [id_list]
+ constraints = filter(lambda x:x.id in id_list, constraints)
+ return constraints
# Context related methods
security.declarePublic('asContext')
Modified: erp5/trunk/products/ERP5Type/Core/Folder.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Core/Folder.py?rev=34873&r1=34872&r2=34873&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Core/Folder.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Core/Folder.py [utf8] Fri Apr 30 10:09:52 2010
@@ -1257,7 +1257,7 @@
security.declareProtected(Permissions.AccessContentsInformation,
'checkConsistency')
- def checkConsistency(self, fixit=0):
+ def checkConsistency(self, fixit=False, filter=None, **kw):
"""
Check the consistency of this object, then
check recursively the consistency of every sub object.
@@ -1272,7 +1272,7 @@
error_list += [(self.getRelativeUrl(), 'BTree Inconsistency',
199, '(fixed)')]
# Call superclass
- error_list += Base.checkConsistency(self, fixit=fixit)
+ error_list += Base.checkConsistency(self, fixit=fixit, filter=filter, **kw)
# We must commit before listing folder contents
# in case we erased some data
if fixit:
@@ -1280,9 +1280,9 @@
# Then check the consistency on all sub objects
for obj in self.contentValues():
if fixit:
- extra_errors = obj.fixConsistency()
+ extra_errors = obj.fixConsistency(filter=filter, **kw)
else:
- extra_errors = obj.checkConsistency()
+ extra_errors = obj.checkConsistency(filter=filter, **kw)
if len(extra_errors) > 0:
error_list += extra_errors
# We should also return an error if any
Modified: erp5/trunk/products/ERP5Type/interfaces/constraint.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/interfaces/constraint.py?rev=34873&r1=34872&r2=34873&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/interfaces/constraint.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/interfaces/constraint.py [utf8] Fri Apr 30 10:09:52 2010
@@ -84,12 +84,17 @@
recursivly.
"""
- def checkConsistency(obj, fixit=0):
+ def checkConsistency(obj, fixit=False, filter=None, **kw):
"""This method checks the consistency of object 'obj', and fix errors if
the argument 'fixit' is true. Not all constraint have to support error
repairing, in that case, simply ignore the fixit parameter. This method
should return a list of errors, which are a list of `ConsistencyMessage`,
with a `getTranslatedMessage` method for user interaction.
+
+ If filter is specified, only constraints filtered by the filter
+ argument are checked.
+
+ Additional argument **kw is passed to each constraint.
"""
_message_id_list = Attribute("The list of messages IDs that can be "
More information about the Erp5-report
mailing list