Commit 76090699 authored by Jérome Perrin's avatar Jérome Perrin

rename checkConsistency argument to 'obj', because object is a builtin


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@10131 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c4fa5b87
...@@ -1811,9 +1811,9 @@ class Base( CopyContainer, PortalContent, ActiveObject, Historical, ERP5Property ...@@ -1811,9 +1811,9 @@ class Base( CopyContainer, PortalContent, ActiveObject, Historical, ERP5Property
for constraint_instance in self.constraints: for constraint_instance in self.constraints:
if fixit: if fixit:
error_list += constraint_instance.fixConsistency(object=self) error_list += constraint_instance.fixConsistency(self)
else: else:
error_list += constraint_instance.checkConsistency(object=self) error_list += constraint_instance.checkConsistency(self)
if len(error_list) > 0 and fixit: if len(error_list) > 0 and fixit:
self.reindexObject() self.reindexObject()
......
...@@ -42,41 +42,41 @@ class AttributeEquality(PropertyExistence): ...@@ -42,41 +42,41 @@ class AttributeEquality(PropertyExistence):
}, },
""" """
def checkConsistency(self, object, fixit=0): def checkConsistency(self, obj, fixit=0):
""" """
This is the check method, we return a list of string, This is the check method, we return a list of string,
each string corresponds to an error. each string corresponds to an error.
We will make sure that each non None constraint_definition is We will make sure that each non None constraint_definition is
satisfied (equality) satisfied (equality)
""" """
errors = PropertyExistence.checkConsistency(self, object, fixit=fixit) errors = PropertyExistence.checkConsistency(self, obj, fixit=fixit)
for attribute_name, attribute_value in self.constraint_definition.items(): for attribute_name, attribute_value in self.constraint_definition.items():
error_message = None error_message = None
# If property does not exist, error will be raise by # If property does not exist, error will be raise by
# PropertyExistence Constraint. # PropertyExistence Constraint.
if object.hasProperty(attribute_name): if obj.hasProperty(attribute_name):
identical = 1 identical = 1
if type(attribute_value) in (type(()), type([])): if type(attribute_value) in (type(()), type([])):
# List type # List type
if len(object.getProperty(attribute_name)) != len(attribute_value): if len(obj.getProperty(attribute_name)) != len(attribute_value):
identical = 0 identical = 0
else: else:
for item in object.getProperty(attribute_name): for item in obj.getProperty(attribute_name):
if item not in attribute_value: if item not in attribute_value:
identical = 0 identical = 0
break break
else: else:
# Other type # Other type
identical = (attribute_value == object.getProperty(attribute_name)) identical = (attribute_value == obj.getProperty(attribute_name))
if not identical: if not identical:
# Generate error_message # Generate error_message
error_message = "Attribute %s is '%s' but should be '%s'" % \ error_message = "Attribute %s is '%s' but should be '%s'" % \
(attribute_name, object.getProperty(attribute_name), (attribute_name, obj.getProperty(attribute_name),
attribute_value) attribute_value)
# Generate error # Generate error
if error_message is not None: if error_message is not None:
if fixit: if fixit:
object._setProperty(attribute_name, attribute_value) obj._setProperty(attribute_name, attribute_value)
error_message += " (Fixed)" error_message += " (Fixed)"
errors.append(self._generateError(object, error_message)) errors.append(self._generateError(obj, error_message))
return errors return errors
...@@ -45,7 +45,7 @@ class CategoryAcquiredMembershipArity(Constraint): ...@@ -45,7 +45,7 @@ class CategoryAcquiredMembershipArity(Constraint):
}, },
""" """
def checkConsistency(self, object, fixit=0): def checkConsistency(self, obj, fixit=0):
""" """
This is the check method, we return a list of string, This is the check method, we return a list of string,
each string corresponds to an error. each string corresponds to an error.
...@@ -60,7 +60,7 @@ class CategoryAcquiredMembershipArity(Constraint): ...@@ -60,7 +60,7 @@ class CategoryAcquiredMembershipArity(Constraint):
max_arity = int(self.constraint_definition['max_arity']) max_arity = int(self.constraint_definition['max_arity'])
portal_type = self.constraint_definition['portal_type'] portal_type = self.constraint_definition['portal_type']
# Check arity and compare it with the min and max # Check arity and compare it with the min and max
arity = len(object.getAcquiredCategoryMembershipList(base_category, arity = len(obj.getAcquiredCategoryMembershipList(base_category,
portal_type=portal_type)) portal_type=portal_type))
if (arity < min_arity) or (arity > max_arity): if (arity < min_arity) or (arity > max_arity):
# Generate error message # Generate error message
...@@ -72,5 +72,5 @@ class CategoryAcquiredMembershipArity(Constraint): ...@@ -72,5 +72,5 @@ class CategoryAcquiredMembershipArity(Constraint):
", arity is equal to %i but should be between %i and %i" % \ ", arity is equal to %i but should be between %i and %i" % \
(arity, min_arity, max_arity) (arity, min_arity, max_arity)
# Add error # Add error
errors.append(self._generateError(object, error_message)) errors.append(self._generateError(obj, error_message))
return errors return errors
...@@ -42,7 +42,7 @@ class CategoryExistence(Constraint): ...@@ -42,7 +42,7 @@ class CategoryExistence(Constraint):
}, },
""" """
def checkConsistency(self, object, fixit=0): def checkConsistency(self, obj, fixit=0):
""" """
This is the check method, we return a list of string, This is the check method, we return a list of string,
each string corresponds to an error. each string corresponds to an error.
...@@ -56,9 +56,9 @@ class CategoryExistence(Constraint): ...@@ -56,9 +56,9 @@ class CategoryExistence(Constraint):
# Check existence of base category # Check existence of base category
error_message = "Category existence error for base category '%s': " % \ error_message = "Category existence error for base category '%s': " % \
base_category base_category
if base_category not in object.getBaseCategoryList(): if base_category not in obj.getBaseCategoryList():
error_message += " this document has no such category" error_message += " this document has no such category"
elif len(object.getCategoryMembershipList(base_category, elif len(obj.getCategoryMembershipList(base_category,
portal_type = self.constraint_definition\ portal_type = self.constraint_definition\
.get('portal_type', ()))) == 0: .get('portal_type', ()))) == 0:
error_message += " this category was not defined" error_message += " this category was not defined"
...@@ -67,6 +67,6 @@ class CategoryExistence(Constraint): ...@@ -67,6 +67,6 @@ class CategoryExistence(Constraint):
# Raise error # Raise error
if error_message: if error_message:
errors.append(self._generateError(object, error_message)) errors.append(self._generateError(obj, error_message))
return errors return errors
...@@ -45,7 +45,7 @@ class CategoryMembershipArity(Constraint): ...@@ -45,7 +45,7 @@ class CategoryMembershipArity(Constraint):
}, },
""" """
def checkConsistency(self, object, fixit=0): def checkConsistency(self, obj, fixit=0):
""" """
This is the check method, we return a list of string, This is the check method, we return a list of string,
each string corresponds to an error. each string corresponds to an error.
...@@ -60,7 +60,7 @@ class CategoryMembershipArity(Constraint): ...@@ -60,7 +60,7 @@ class CategoryMembershipArity(Constraint):
max_arity = int(self.constraint_definition['max_arity']) max_arity = int(self.constraint_definition['max_arity'])
portal_type = self.constraint_definition['portal_type'] portal_type = self.constraint_definition['portal_type']
# Check arity and compare it with the min and max # Check arity and compare it with the min and max
arity = len(object.getCategoryMembershipList(base_category, arity = len(obj.getCategoryMembershipList(base_category,
portal_type=portal_type)) portal_type=portal_type))
if (arity < min_arity) or (arity > max_arity): if (arity < min_arity) or (arity > max_arity):
# Generate error message # Generate error message
...@@ -72,5 +72,5 @@ class CategoryMembershipArity(Constraint): ...@@ -72,5 +72,5 @@ class CategoryMembershipArity(Constraint):
", arity is equal to %i but should be between %i and %i" % \ ", arity is equal to %i but should be between %i and %i" % \
(arity, min_arity, max_arity) (arity, min_arity, max_arity)
# Add error # Add error
errors.append(self._generateError(object, error_message)) errors.append(self._generateError(obj, error_message))
return errors return errors
...@@ -46,7 +46,7 @@ class CategoryRelatedMembershipArity(Constraint): ...@@ -46,7 +46,7 @@ class CategoryRelatedMembershipArity(Constraint):
}, },
""" """
def checkConsistency(self, object, fixit=0): def checkConsistency(self, obj, fixit=0):
""" """
This is the check method, we return a list of string, This is the check method, we return a list of string,
each string corresponds to an error. each string corresponds to an error.
...@@ -61,7 +61,7 @@ class CategoryRelatedMembershipArity(Constraint): ...@@ -61,7 +61,7 @@ class CategoryRelatedMembershipArity(Constraint):
max_arity = int(self.constraint_definition['max_arity']) max_arity = int(self.constraint_definition['max_arity'])
portal_type = self.constraint_definition['portal_type'] portal_type = self.constraint_definition['portal_type']
# Check arity and compare it with the min and max # Check arity and compare it with the min and max
arity = len(object._getRelatedValueList(base_category, arity = len(obj._getRelatedValueList(base_category,
portal_type=portal_type)) portal_type=portal_type))
if (arity < min_arity) or (arity > max_arity): if (arity < min_arity) or (arity > max_arity):
# Generate error message # Generate error message
...@@ -73,5 +73,5 @@ class CategoryRelatedMembershipArity(Constraint): ...@@ -73,5 +73,5 @@ class CategoryRelatedMembershipArity(Constraint):
", arity is equal to %i but should be between %i and %i" % \ ", arity is equal to %i but should be between %i and %i" % \
(arity, min_arity, max_arity) (arity, min_arity, max_arity)
# Add error # Add error
errors.append(self._generateError(object, error_message)) errors.append(self._generateError(obj, error_message))
return errors return errors
...@@ -33,7 +33,7 @@ class Constraint: ...@@ -33,7 +33,7 @@ class Constraint:
Default Constraint implementation Default Constraint implementation
""" """
def __init__(self, id=None, description=None, type=None, def __init__(self, id=None, description=None, type=None,
**constraint_definition): **constraint_definition):
""" """
Remove unwanted attributes from constraint definition and keep Remove unwanted attributes from constraint definition and keep
...@@ -44,7 +44,7 @@ class Constraint: ...@@ -44,7 +44,7 @@ class Constraint:
self.type = type self.type = type
self.constraint_definition = constraint_definition self.constraint_definition = constraint_definition
def edit(self, id=None, description=None, type=None, def edit(self, id=None, description=None, type=None,
**constraint_definition): **constraint_definition):
""" """
Remove unwanted attributes from constraint definition and keep Remove unwanted attributes from constraint definition and keep
...@@ -55,27 +55,28 @@ class Constraint: ...@@ -55,27 +55,28 @@ class Constraint:
if type is not None: self.type = type if type is not None: self.type = type
self.constraint_definition.update(constraint_definition) self.constraint_definition.update(constraint_definition)
def _generateError(self, object, error_message): def _generateError(self, obj, error_message):
""" """
Generic method used to generate error in checkConsistency. Generic method used to generate error in checkConsistency.
""" """
error = None error = None
if error_message: if error_message:
error = (object.getRelativeUrl(), error = (obj.getRelativeUrl(),
'%s inconsistency' % self.__class__.__name__, '%s inconsistency' % self.__class__.__name__,
104, error_message, self.description) 104, error_message, self.description)
return error return error
def checkConsistency(self, object, fixit=0): def checkConsistency(self, obj, fixit=0):
""" """
Default method is to return no error. Default method is to return no error.
""" """
errors = [] errors = []
return errors return errors
def fixConsistency(self, object): def fixConsistency(self, obj):
""" """
Default method is to call checkConsistency with Default method is to call checkConsistency with
fixit set to 1 fixit set to 1
""" """
return self.checkConsistency(object, fixit=1) return self.checkConsistency(obj, fixit=1)
...@@ -46,13 +46,11 @@ class PortalTypeClass(Constraint): ...@@ -46,13 +46,11 @@ class PortalTypeClass(Constraint):
}, },
""" """
def checkConsistency(self, object, fixit=0): def checkConsistency(self, obj, fixit=0):
""" """
This is the check method, we return a list of string, This is the check method, we return a list of string,
each string corresponds to an error. each string corresponds to an error.
""" """
obj = object # FIXME: default argument should not use `object`
# from python builtins
errors = [] errors = []
types_tool = getToolByName(obj, 'portal_types') types_tool = getToolByName(obj, 'portal_types')
type_info = types_tool._getOb(obj.getPortalType(), None) type_info = types_tool._getOb(obj.getPortalType(), None)
......
...@@ -43,7 +43,7 @@ class PropertyExistence(Constraint): ...@@ -43,7 +43,7 @@ class PropertyExistence(Constraint):
}, },
""" """
def checkConsistency(self, object, fixit=0): def checkConsistency(self, obj, fixit=0):
""" """
This is the check method, we return a list of string, This is the check method, we return a list of string,
each string corresponds to an error. each string corresponds to an error.
...@@ -54,16 +54,16 @@ class PropertyExistence(Constraint): ...@@ -54,16 +54,16 @@ class PropertyExistence(Constraint):
# Check existence of property # Check existence of property
error_message = \ error_message = \
"Property existence error for property '%s': " % property_id "Property existence error for property '%s': " % property_id
if not object.hasProperty(property_id): if not obj.hasProperty(property_id):
error_message += " this document has no such property" error_message += " this document has no such property"
elif object.getProperty(property_id) is None: elif obj.getProperty(property_id) is None:
# If value is '', attribute is considered a defined # If value is '', attribute is considered a defined
# XXX is this the default API ? # XXX is this the default API ?
error_message += " this property was not defined" error_message += " this property was not defined"
else: else:
error_message = None error_message = None
# Return error # Return error
error = self._generateError(object, error_message) error = self._generateError(obj, error_message)
if error is not None: if error is not None:
errors.append(error) errors.append(error)
return errors return errors
...@@ -54,21 +54,21 @@ class PropertyTypeValidity(Constraint): ...@@ -54,21 +54,21 @@ class PropertyTypeValidity(Constraint):
'date': (type(DateTime()), ), 'date': (type(DateTime()), ),
} }
def checkConsistency(self, object, fixit=0): def checkConsistency(self, obj, fixit=0):
""" """
This is the check method, we return a list of string, This is the check method, we return a list of string,
each string corresponds to an error. each string corresponds to an error.
""" """
errors = [] errors = []
# For each attribute name, we check type # For each attribute name, we check type
for property in object.propertyMap(): for prop in obj.propertyMap():
property_id = property['id'] property_id = prop['id']
if property.get('multivalued', 0): if prop.get('multivalued', 0):
property_type = 'lines' property_type = 'lines'
else: else:
property_type = property['type'] property_type = prop['type']
wrong_type = 0 wrong_type = 0
value = object.getProperty(property_id) value = obj.getProperty(property_id)
if value is not None: if value is not None:
# Check known type # Check known type
try: try:
...@@ -77,7 +77,7 @@ class PropertyTypeValidity(Constraint): ...@@ -77,7 +77,7 @@ class PropertyTypeValidity(Constraint):
wrong_type = 0 wrong_type = 0
error_message = "Attribute %s is defined with unknown type %s" % \ error_message = "Attribute %s is defined with unknown type %s" % \
(property_id, property_type) (property_id, property_type)
errors.append(self._generateError(object, error_message)) errors.append(self._generateError(obj, error_message))
if wrong_type: if wrong_type:
# Type is wrong, so, raise constraint error # Type is wrong, so, raise constraint error
error_message = \ error_message = \
...@@ -91,7 +91,7 @@ class PropertyTypeValidity(Constraint): ...@@ -91,7 +91,7 @@ class PropertyTypeValidity(Constraint):
except (KeyError, ValueError), error: except (KeyError, ValueError), error:
error_message += " (Type cast failed : %s)" % error error_message += " (Type cast failed : %s)" % error
else: else:
object.setProperty(property_id, value) obj.setProperty(property_id, value)
error_message += " (Fixed)" error_message += " (Fixed)"
errors.append(self._generateError(object, error_message)) errors.append(self._generateError(obj, error_message))
return errors return errors
...@@ -581,7 +581,7 @@ class ConstraintTemplate(Constraint): ...@@ -581,7 +581,7 @@ class ConstraintTemplate(Constraint):
Explain here what this constraint checker does Explain here what this constraint checker does
\"\"\" \"\"\"
def checkConsistency(self, object, fixit = 0): def checkConsistency(self, obj, fixit = 0):
\"\"\" \"\"\"
Implement here the consistency checker Implement here the consistency checker
whenever fixit is not 0, object data should be updated to whenever fixit is not 0, object data should be updated to
......
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