Commit 736a4382 authored by Arnaud Fontaine's avatar Arnaud Fontaine

AttributeEqualityConstraint for ZODB Property Sheet should have always

inherited from PropertyExistenceConstraint


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@41835 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent da324b53
...@@ -29,11 +29,14 @@ ...@@ -29,11 +29,14 @@
# #
############################################################################## ##############################################################################
from Products.ERP5Type.Core.PropertyExistenceConstraint import \
PropertyExistenceConstraint
from Products.ERP5Type.mixin.constraint import ConstraintMixin from Products.ERP5Type.mixin.constraint import ConstraintMixin
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
class AttributeEqualityConstraint(ConstraintMixin): class AttributeEqualityConstraint(PropertyExistenceConstraint):
""" """
This constraint checks the values of a given attribute name on this This constraint checks the values of a given attribute name on this
object. object.
...@@ -68,46 +71,45 @@ class AttributeEqualityConstraint(ConstraintMixin): ...@@ -68,46 +71,45 @@ class AttributeEqualityConstraint(ConstraintMixin):
""" """
attribute_name = self.getConstraintAttributeName() attribute_name = self.getConstraintAttributeName()
# If property does not exist, error will be raised by error = self._checkPropertyConsistency(obj, attribute_name)
# PropertyExistence Constraint, but the value has to be set at if error:
# least once as there is no need to perform any check if it is the return [error]
# default value
if obj.hasProperty(attribute_name): identical = True
identical = True
# The expected value of the attribute is a TALES Expression
# The expected value of the attribute is a TALES Expression attribute_expected_value = self._getExpressionValue(
attribute_expected_value = self._getExpressionValue( obj, self.getConstraintAttributeValue())
obj, self.getConstraintAttributeValue())
attribute_value = obj.getProperty(attribute_name)
attribute_value = obj.getProperty(attribute_name)
if isinstance(attribute_expected_value, (list, tuple)):
if isinstance(attribute_expected_value, (list, tuple)): # List type
# List type if len(attribute_value) != len(attribute_expected_value):
if len(attribute_value) != len(attribute_expected_value): identical = False
identical = False else:
else: for item in attribute_value:
for item in attribute_value: if item not in attribute_expected_value:
if item not in attribute_expected_value: identical = False
identical = False break
break else:
# Other primitive type
identical = (attribute_expected_value == attribute_value)
if not identical:
# Generate error and fix it if required
if fixit:
obj._setProperty(attribute_name, attribute_expected_value)
message_id = 'message_invalid_attribute_value_fixed'
else: else:
# Other primitive type message_id = 'message_invalid_attribute_value'
identical = (attribute_expected_value == attribute_value)
error = self._generateError(
if not identical: obj, self._getMessage(message_id),
# Generate error and fix it if required dict(attribute_name=attribute_name,
if fixit: current_value=attribute_value,
obj._setProperty(attribute_name, attribute_expected_value) expected_value=attribute_expected_value))
message_id = 'message_invalid_attribute_value_fixed'
else: return [error]
message_id = 'message_invalid_attribute_value'
error = self._generateError(
obj, self._getMessage(message_id),
dict(attribute_name=attribute_name,
current_value=attribute_value,
expected_value=attribute_expected_value))
return [error]
return [] return []
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