From 1e9848e0d00b36398d4c46ad88512820f7ee7080 Mon Sep 17 00:00:00 2001 From: Arnaud Fontaine <arnaud.fontaine@nexedi.com> Date: Tue, 28 Dec 2010 12:15:52 +0000 Subject: [PATCH] Get rid of useless getProperty() (see r41787) and add a method which checks only one property so it could be used in child constraints checking only one property git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@41824 20353a03-c40f-0410-a6d1-a30d3c3de9de --- .../Core/PropertyExistenceConstraint.py | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/product/ERP5Type/Core/PropertyExistenceConstraint.py b/product/ERP5Type/Core/PropertyExistenceConstraint.py index 993d38d20c..bb67771ad0 100644 --- a/product/ERP5Type/Core/PropertyExistenceConstraint.py +++ b/product/ERP5Type/Core/PropertyExistenceConstraint.py @@ -57,26 +57,29 @@ class PropertyExistenceConstraint(ConstraintMixin): property_sheets = ConstraintMixin.property_sheets + \ (PropertySheet.PropertyExistenceConstraint,) - def _checkConsistency(self, obj, fixit=0): + def _checkPropertyConsistency(self, obj, property_id): + """ + Check the consistency of the object only for the given Property ID + and is meaningful for child constraints which only need to check + one property + """ + # Check whether the property exists and has been set + if not obj.hasProperty(property_id): + return "message_property_not_set" + + return None + + def _checkConsistency(self, obj, fixit=False): """ Check the object's consistency. """ error_list = [] # For each attribute name, we check if defined for property_id in self.getConstraintPropertyList(): - # Check existence of property - mapping = dict(property_id=property_id) - if not obj.hasProperty(property_id): - error_message_id = "message_no_such_property" - elif obj.getProperty(property_id) is None: - # If value is '', attribute is considered a defined - # XXX is this the default API ? - error_message_id = "message_property_not_set" - else: - error_message_id = None - - if error_message_id: + error_message_id = self._checkPropertyConsistency(obj, property_id) + if error_message_id is not None: error_list.append(self._generateError( - obj, self._getMessage(error_message_id), mapping)) + obj, self._getMessage(error_message_id), + dict(property_id=property_id))) return error_list -- 2.30.9