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
for constraint_instance in self.constraints:
if fixit:
error_list += constraint_instance.fixConsistency(object=self)
error_list += constraint_instance.fixConsistency(self)
else:
error_list += constraint_instance.checkConsistency(object=self)
error_list += constraint_instance.checkConsistency(self)
if len(error_list) > 0 and fixit:
self.reindexObject()
......
......@@ -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,
each string corresponds to an error.
We will make sure that each non None constraint_definition is
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():
error_message = None
# If property does not exist, error will be raise by
# PropertyExistence Constraint.
if object.hasProperty(attribute_name):
if obj.hasProperty(attribute_name):
identical = 1
if type(attribute_value) in (type(()), type([])):
# List type
if len(object.getProperty(attribute_name)) != len(attribute_value):
if len(obj.getProperty(attribute_name)) != len(attribute_value):
identical = 0
else:
for item in object.getProperty(attribute_name):
for item in obj.getProperty(attribute_name):
if item not in attribute_value:
identical = 0
break
else:
# Other type
identical = (attribute_value == object.getProperty(attribute_name))
identical = (attribute_value == obj.getProperty(attribute_name))
if not identical:
# Generate error_message
error_message = "Attribute %s is '%s' but should be '%s'" % \
(attribute_name, object.getProperty(attribute_name),
(attribute_name, obj.getProperty(attribute_name),
attribute_value)
# Generate error
if error_message is not None:
if fixit:
object._setProperty(attribute_name, attribute_value)
obj._setProperty(attribute_name, attribute_value)
error_message += " (Fixed)"
errors.append(self._generateError(object, error_message))
errors.append(self._generateError(obj, error_message))
return errors
......@@ -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,
each string corresponds to an error.
......@@ -60,7 +60,7 @@ class CategoryAcquiredMembershipArity(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(object.getAcquiredCategoryMembershipList(base_category,
arity = len(obj.getAcquiredCategoryMembershipList(base_category,
portal_type=portal_type))
if (arity < min_arity) or (arity > max_arity):
# Generate error message
......@@ -72,5 +72,5 @@ class CategoryAcquiredMembershipArity(Constraint):
", arity is equal to %i but should be between %i and %i" % \
(arity, min_arity, max_arity)
# Add error
errors.append(self._generateError(object, error_message))
errors.append(self._generateError(obj, error_message))
return errors
......@@ -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,
each string corresponds to an error.
......@@ -56,9 +56,9 @@ class CategoryExistence(Constraint):
# Check existence of base category
error_message = "Category existence error for base category '%s': " % \
base_category
if base_category not in object.getBaseCategoryList():
if base_category not in obj.getBaseCategoryList():
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\
.get('portal_type', ()))) == 0:
error_message += " this category was not defined"
......@@ -67,6 +67,6 @@ class CategoryExistence(Constraint):
# Raise error
if error_message:
errors.append(self._generateError(object, error_message))
errors.append(self._generateError(obj, error_message))
return errors
......@@ -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,
each string corresponds to an error.
......@@ -60,7 +60,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(object.getCategoryMembershipList(base_category,
arity = len(obj.getCategoryMembershipList(base_category,
portal_type=portal_type))
if (arity < min_arity) or (arity > max_arity):
# Generate error message
......@@ -72,5 +72,5 @@ class CategoryMembershipArity(Constraint):
", arity is equal to %i but should be between %i and %i" % \
(arity, min_arity, max_arity)
# Add error
errors.append(self._generateError(object, error_message))
errors.append(self._generateError(obj, error_message))
return errors
......@@ -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,
each string corresponds to an error.
......@@ -61,7 +61,7 @@ class CategoryRelatedMembershipArity(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(object._getRelatedValueList(base_category,
arity = len(obj._getRelatedValueList(base_category,
portal_type=portal_type))
if (arity < min_arity) or (arity > max_arity):
# Generate error message
......@@ -73,5 +73,5 @@ class CategoryRelatedMembershipArity(Constraint):
", arity is equal to %i but should be between %i and %i" % \
(arity, min_arity, max_arity)
# Add error
errors.append(self._generateError(object, error_message))
errors.append(self._generateError(obj, error_message))
return errors
......@@ -33,7 +33,7 @@ class Constraint:
Default Constraint implementation
"""
def __init__(self, id=None, description=None, type=None,
def __init__(self, id=None, description=None, type=None,
**constraint_definition):
"""
Remove unwanted attributes from constraint definition and keep
......@@ -44,7 +44,7 @@ class Constraint:
self.type = type
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):
"""
Remove unwanted attributes from constraint definition and keep
......@@ -55,27 +55,28 @@ class Constraint:
if type is not None: self.type = type
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.
"""
error = None
if error_message:
error = (object.getRelativeUrl(),
'%s inconsistency' % self.__class__.__name__,
error = (obj.getRelativeUrl(),
'%s inconsistency' % self.__class__.__name__,
104, error_message, self.description)
return error
def checkConsistency(self, object, fixit=0):
def checkConsistency(self, obj, fixit=0):
"""
Default method is to return no error.
"""
errors = []
return errors
def fixConsistency(self, object):
def fixConsistency(self, obj):
"""
Default method is to call checkConsistency with
fixit set to 1
"""
return self.checkConsistency(object, fixit=1)
return self.checkConsistency(obj, fixit=1)
......@@ -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,
each string corresponds to an error.
"""
obj = object # FIXME: default argument should not use `object`
# from python builtins
errors = []
types_tool = getToolByName(obj, 'portal_types')
type_info = types_tool._getOb(obj.getPortalType(), None)
......
......@@ -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,
each string corresponds to an error.
......@@ -54,16 +54,16 @@ class PropertyExistence(Constraint):
# Check existence of property
error_message = \
"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"
elif object.getProperty(property_id) is None:
elif obj.getProperty(property_id) is None:
# If value is '', attribute is considered a defined
# XXX is this the default API ?
error_message += " this property was not defined"
else:
error_message = None
# Return error
error = self._generateError(object, error_message)
error = self._generateError(obj, error_message)
if error is not None:
errors.append(error)
return errors
......@@ -54,21 +54,21 @@ class PropertyTypeValidity(Constraint):
'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,
each string corresponds to an error.
"""
errors = []
# For each attribute name, we check type
for property in object.propertyMap():
property_id = property['id']
if property.get('multivalued', 0):
for prop in obj.propertyMap():
property_id = prop['id']
if prop.get('multivalued', 0):
property_type = 'lines'
else:
property_type = property['type']
property_type = prop['type']
wrong_type = 0
value = object.getProperty(property_id)
value = obj.getProperty(property_id)
if value is not None:
# Check known type
try:
......@@ -77,7 +77,7 @@ class PropertyTypeValidity(Constraint):
wrong_type = 0
error_message = "Attribute %s is defined with unknown type %s" % \
(property_id, property_type)
errors.append(self._generateError(object, error_message))
errors.append(self._generateError(obj, error_message))
if wrong_type:
# Type is wrong, so, raise constraint error
error_message = \
......@@ -91,7 +91,7 @@ class PropertyTypeValidity(Constraint):
except (KeyError, ValueError), error:
error_message += " (Type cast failed : %s)" % error
else:
object.setProperty(property_id, value)
obj.setProperty(property_id, value)
error_message += " (Fixed)"
errors.append(self._generateError(object, error_message))
errors.append(self._generateError(obj, error_message))
return errors
......@@ -581,7 +581,7 @@ class ConstraintTemplate(Constraint):
Explain here what this constraint checker does
\"\"\"
def checkConsistency(self, object, fixit = 0):
def checkConsistency(self, obj, fixit = 0):
\"\"\"
Implement here the consistency checker
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