Commit 7efe448b authored by Jérome Perrin's avatar Jérome Perrin

CategoryRelatedMembershipArity and CategoryAcquiredMembershipArity were sharing

too much code with CategoryMembershipArity, so make them subclass
CategoryMembershipArity and redefine only the different part



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@18226 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ddde48e0
......@@ -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 @@ class CategoryAcquiredMembershipArity(Constraint):
},
"""
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,
return 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
......@@ -46,6 +46,12 @@ class CategoryMembershipArity(Constraint):
},
"""
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 @@ class CategoryMembershipArity(Constraint):
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
......
......@@ -28,8 +28,10 @@
##############################################################################
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.
......@@ -47,42 +49,9 @@ class CategoryRelatedMembershipArity(Constraint):
},
"""
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 = 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,
return 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
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