[Erp5-report] r18226 - /erp5/trunk/products/ERP5Type/Constraint/
nobody at svn.erp5.org
nobody at svn.erp5.org
Tue Dec 11 13:34:45 CET 2007
Author: jerome
Date: Tue Dec 11 13:34:44 2007
New Revision: 18226
URL: http://svn.erp5.org?rev=18226&view=rev
Log:
CategoryRelatedMembershipArity and CategoryAcquiredMembershipArity were sharing
too much code with CategoryMembershipArity, so make them subclass
CategoryMembershipArity and redefine only the different part
Modified:
erp5/trunk/products/ERP5Type/Constraint/CategoryAcquiredMembershipArity.py
erp5/trunk/products/ERP5Type/Constraint/CategoryMembershipArity.py
erp5/trunk/products/ERP5Type/Constraint/CategoryRelatedMembershipArity.py
Modified: erp5/trunk/products/ERP5Type/Constraint/CategoryAcquiredMembershipArity.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Constraint/CategoryAcquiredMembershipArity.py?rev=18226&r1=18225&r2=18226&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Constraint/CategoryAcquiredMembershipArity.py (original)
+++ erp5/trunk/products/ERP5Type/Constraint/CategoryAcquiredMembershipArity.py Tue Dec 11 13:34:44 2007
@@ -28,8 +28,10 @@
##############################################################################
from Constraint import Constraint
+from Products.ERP5Type.Constraint.CategoryMembershipArity \
+ import CategoryMembershipArity
-class CategoryAcquiredMembershipArity(Constraint):
+class CategoryAcquiredMembershipArity(CategoryMembershipArity):
"""
This method check and fix if an object respects the arity.
For example we can check if every Order has at
@@ -46,34 +48,9 @@
},
"""
- def checkConsistency(self, obj, fixit=0):
- """
- This is the check method, we return a list of string,
- each string corresponds to an error.
- We are looking the definition of the constraing where
- are defined the minimum and the maximum arity, and the
- list of objects we wants to check the arity.
- """
- if not self._checkConstraintCondition(obj):
- return []
- errors = []
- # Retrieve values inside de PropertySheet (_constraints)
+ def _calculateArity(self, obj):
base_category = self.constraint_definition['base_category']
- min_arity = int(self.constraint_definition['min_arity'])
- max_arity = int(self.constraint_definition['max_arity'])
portal_type = self.constraint_definition['portal_type']
- # Check arity and compare it with the min and max
- arity = len(obj.getAcquiredCategoryMembershipList(base_category,
- portal_type=portal_type))
- if (arity < min_arity) or (arity > max_arity):
- # Generate error message
- error_message = "Arity error for relation '%s'" % \
- base_category
- if portal_type is not ():
- error_message += " and portal_type: '%s'" % str(portal_type)
- error_message += \
- ", arity is equal to %i but should be between %i and %i" % \
- (arity, min_arity, max_arity)
- # Add error
- errors.append(self._generateError(obj, error_message))
- return errors
+ return len(obj.getAcquiredCategoryMembershipList(base_category,
+ portal_type=portal_type))
+
Modified: erp5/trunk/products/ERP5Type/Constraint/CategoryMembershipArity.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Constraint/CategoryMembershipArity.py?rev=18226&r1=18225&r2=18226&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Constraint/CategoryMembershipArity.py (original)
+++ erp5/trunk/products/ERP5Type/Constraint/CategoryMembershipArity.py Tue Dec 11 13:34:44 2007
@@ -46,6 +46,12 @@
},
"""
+ def _calculateArity(self, obj):
+ base_category = self.constraint_definition['base_category']
+ portal_type = self.constraint_definition['portal_type']
+ return len(obj.getCategoryMembershipList(base_category,
+ portal_type=portal_type))
+
def checkConsistency(self, obj, fixit=0):
"""
This is the check method, we return a list of string,
@@ -65,8 +71,7 @@
max_arity = int(self.constraint_definition['max_arity'])
portal_type = self.constraint_definition['portal_type']
# Check arity and compare it with the min and max
- arity = len(obj.getCategoryMembershipList(base_category,
- portal_type=portal_type))
+ arity = self._calculateArity(obj)
if not (max_arity is None and (min_arity <= arity)
or (min_arity <= arity <= max_arity)):
# Generate error message
Modified: erp5/trunk/products/ERP5Type/Constraint/CategoryRelatedMembershipArity.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Constraint/CategoryRelatedMembershipArity.py?rev=18226&r1=18225&r2=18226&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Constraint/CategoryRelatedMembershipArity.py (original)
+++ erp5/trunk/products/ERP5Type/Constraint/CategoryRelatedMembershipArity.py Tue Dec 11 13:34:44 2007
@@ -28,9 +28,11 @@
##############################################################################
from Constraint import Constraint
+from Products.ERP5Type.Constraint.CategoryMembershipArity \
+ import CategoryMembershipArity
-class CategoryRelatedMembershipArity(Constraint):
- """
+class CategoryRelatedMembershipArity(CategoryMembershipArity):
+ """
This method check and fix if an object respects the arity
from a category reverse membership point of view.
For example we can check if every Order has at
@@ -45,44 +47,11 @@
'base_category' : ('causality',)
'condition' : 'python: object.getPortalType() == 'Foo',
},
- """
+ """
+
+ def _calculateArity(self, obj):
+ base_category = self.constraint_definition['base_category']
+ portal_type = self.constraint_definition['portal_type']
+ return len(obj._getRelatedValueList(base_category,
+ portal_type=portal_type))
- def checkConsistency(self, obj, fixit=0):
- """
- This is the check method, we return a list of string,
- each string corresponds to an error.
- We are looking the definition of the constraing where
- are defined the minimum and the maximum arity, and the
- list of objects we wants to check the arity.
- """
- if not self._checkConstraintCondition(obj):
- return []
- errors = []
- # Retrieve values inside de PropertySheet (_constraints)
- base_category = self.constraint_definition['base_category']
- min_arity = int(self.constraint_definition['min_arity'])
- max_arity = None
- if 'max_arity' in self.constraint_definition:
- max_arity = int(self.constraint_definition['max_arity'])
- portal_type = self.constraint_definition['portal_type']
- # Check arity and compare it with the min and max
- arity = len(obj._getRelatedValueList(base_category,
- portal_type=portal_type))
- if not (max_arity is None and (min_arity <= arity)
- or (min_arity <= arity <= max_arity)):
- # Generate error message
- error_message = "Arrity error for reverse relation '%s'" % \
- base_category
- if portal_type is not ():
- error_message += " and portal_type: '%s'" % str(portal_type)
- if max_arity is None:
- error_message += \
- ", arity is equal to %i but should be at least %i" % \
- (arity, min_arity)
- else:
- error_message += \
- ", arity is equal to %i but should be between %i and %i" % \
- (arity, min_arity, max_arity)
- # Add error
- errors.append(self._generateError(obj, error_message))
- return errors
More information about the Erp5-report
mailing list