diff --git a/product/ERP5/Constraint/AccountTypeConstraint.py b/product/ERP5/Constraint/AccountTypeConstraint.py index 1a0d3a8d952bbe3d7ba907b25adb3eb5def1662e..1e007e2a7d455e3fe7159e12b2ef80cc03b2a758 100644 --- a/product/ERP5/Constraint/AccountTypeConstraint.py +++ b/product/ERP5/Constraint/AccountTypeConstraint.py @@ -58,12 +58,9 @@ class AccountTypeConstraint(Constraint): ' of ${category}, this should have account_type' ' in ${account_type_list}') - def checkConsistency(self, obj, fixit=0): + def _checkConsistency(self, obj, fixit=0): """Implement here the consistency checker """ - if not self._checkConstraintCondition(obj): - return [] - errors = [] if getattr(obj, 'getAccountType', _MARKER) is _MARKER: errors.append(self._generateError( diff --git a/product/ERP5/Constraint/AccountingTransactionBalance.py b/product/ERP5/Constraint/AccountingTransactionBalance.py index eaba89a12fbef063e189b9903a3240c55b60b691..48ee7f2c2f267d7c0fd474cfe399f4e8b6cabc54 100644 --- a/product/ERP5/Constraint/AccountingTransactionBalance.py +++ b/product/ERP5/Constraint/AccountingTransactionBalance.py @@ -41,12 +41,9 @@ class AccountingTransactionBalance(Constraint): message_transaction_not_balanced_for_destination = translateString( 'Transaction is not balanced for ${section_title}') - def checkConsistency(self, obj, fixit=0): + def _checkConsistency(self, obj, fixit=0): """Implement here the consistency checker """ - if not self._checkConstraintCondition(obj): - return [] - error_list = [] source_sum = dict() destination_sum = dict() diff --git a/product/ERP5/Constraint/BudgetConsumptionFeasability.py b/product/ERP5/Constraint/BudgetConsumptionFeasability.py index 83b07753ff777a6c1d2cb41c68e8d187a6d47591..ec576471d132b44a87eaa3f4f629a2848669695c 100644 --- a/product/ERP5/Constraint/BudgetConsumptionFeasability.py +++ b/product/ERP5/Constraint/BudgetConsumptionFeasability.py @@ -33,13 +33,10 @@ class BudgetConsumptionFeasability(Constraint): Check if there is enough budget to consumed. """ - def checkConsistency(self, object, fixit=0): + def _checkConsistency(self, object, fixit=0): """ Check if there is enough budget to consumed. """ - if not self._checkConstraintCondition(object): - return [] - errors = [] new_category_list = [] diff --git a/product/ERP5/Constraint/DocumentReferenceConstraint.py b/product/ERP5/Constraint/DocumentReferenceConstraint.py index f3d9e234f72a25ea81b077139d9251afea5ad390..4c573309e19b22f08a3bcb611b773ce379bcc1a6 100644 --- a/product/ERP5/Constraint/DocumentReferenceConstraint.py +++ b/product/ERP5/Constraint/DocumentReferenceConstraint.py @@ -54,13 +54,10 @@ class DocumentReferenceConstraint(Constraint): 'Multiple (${document_count}) documents ${document_reference} - ' '${document_language} - ${document_version} already exists') - def checkConsistency(self, document, fixit=0): + def _checkConsistency(self, document, fixit=0): """ Implement here the consistency checker """ - if not self._checkConstraintCondition(document): - return [] - # XXX we probably could check reference syntax here, based on regexp in # preferences? error_list = [] diff --git a/product/ERP5/Constraint/ResourceMeasuresConsistency.py b/product/ERP5/Constraint/ResourceMeasuresConsistency.py index 4506cbb265fc593fb039d2c23d969cd88a353c6f..cb43d99a88c87103731d965bb26ba24552658b02 100644 --- a/product/ERP5/Constraint/ResourceMeasuresConsistency.py +++ b/product/ERP5/Constraint/ResourceMeasuresConsistency.py @@ -54,12 +54,9 @@ class ResourceMeasuresConsistency(Constraint): "Implicit measure for the management unit can't be created" \ " because 'metric_type/${metric_type}' category doesn't exist." - def checkConsistency(self, obj, fixit=0): + def _checkConsistency(self, obj, fixit=0): """Implement here the consistency checker """ - if not self._checkConstraintCondition(obj): - return [] - error_list = [] portal = obj.getPortalObject() diff --git a/product/ERP5/Constraint/TradeModelLineCellConsistency.py b/product/ERP5/Constraint/TradeModelLineCellConsistency.py index 08da757e2d9ff1c4a137eb9a668b930c92bb543e..f404fb79f04bb35355c098fa849760ca4eaad846 100644 --- a/product/ERP5/Constraint/TradeModelLineCellConsistency.py +++ b/product/ERP5/Constraint/TradeModelLineCellConsistency.py @@ -41,13 +41,10 @@ class TradeModelLineCellConsistency(Constraint): message_cell_inexistance = translateString( 'Missing cells on line "${line}"') - def checkConsistency(self, document, fixit=0): + def _checkConsistency(self, document, fixit=0): """ Implement here the consistency checker """ - if not self._checkConstraintCondition(document): - return [] - error_list = [] base_id = self.constraint_definition['base_id'] for cell_coordinates in document.getCellKeyList(base_id=base_id): diff --git a/product/ERP5/Constraint/TransactionQuantityValueFeasability.py b/product/ERP5/Constraint/TransactionQuantityValueFeasability.py index 840bbc00ce6a1f4baf040acd050f9d3ba0742874..7a4e828a0966279493fc14d487de97264b4cee3d 100644 --- a/product/ERP5/Constraint/TransactionQuantityValueFeasability.py +++ b/product/ERP5/Constraint/TransactionQuantityValueFeasability.py @@ -34,14 +34,11 @@ class TransactionQuantityValueFeasability(Constraint): for the source and the destination """ - def checkConsistency(self, object, fixit=0): + def _checkConsistency(self, object, fixit=0): """ Check if the quantity of the transaction is possible for the source and the destination """ - if not self._checkConstraintCondition(object): - return [] - errors = [] source_cell = object.getSourceValue() destination_cell = object.getDestinationValue() diff --git a/product/ERP5/Constraint/TransactionQuantityValueValidity.py b/product/ERP5/Constraint/TransactionQuantityValueValidity.py index d2d62fb60e353c3b3afe23a2e7fe2d3b39698fef..2628eda247f742124a6ae802bd9807bd35ae9c65 100644 --- a/product/ERP5/Constraint/TransactionQuantityValueValidity.py +++ b/product/ERP5/Constraint/TransactionQuantityValueValidity.py @@ -33,14 +33,11 @@ class TransactionQuantityValueValidity(Constraint): Explain here what this constraint checker does """ - def checkConsistency(self, object, fixit=0): + def _checkConsistency(self, object, fixit=0): """ Check if the quantity of the transaction is greater than the balance of the source. """ - if not self._checkConstraintCondition(object): - return [] - errors = [] source_cell = object.getSourceValue() diff --git a/product/ERP5/Document/AccountingTransactionBalanceConstraint.py b/product/ERP5/Document/AccountingTransactionBalanceConstraint.py index 6e9692c38c8d2a8e08d82fb6f15cc523fe03f85e..e1a3b7cac3fc525e5d34fdfb7a2af1d241b7d90a 100644 --- a/product/ERP5/Document/AccountingTransactionBalanceConstraint.py +++ b/product/ERP5/Document/AccountingTransactionBalanceConstraint.py @@ -46,13 +46,10 @@ class AccountingTransactionBalanceConstraint(ConstraintMixin): PropertySheet.Reference, PropertySheet.AccountingTransactionBalanceConstraint) - def checkConsistency(self, obj, fixit=0): + def _checkConsistency(self, obj, fixit=0): """ Check the object's consistency """ - if not self.test(obj): - return [] - error_list = [] source_sum = dict() destination_sum = dict() diff --git a/product/ERP5/Document/ResourceMeasuresConsistencyConstraint.py b/product/ERP5/Document/ResourceMeasuresConsistencyConstraint.py index b0192f2aa2903c5b43a9a4df6f71e5a8eedd9664..d8c65008feb77ef5b8bbafd6d2f85fca1838a239 100644 --- a/product/ERP5/Document/ResourceMeasuresConsistencyConstraint.py +++ b/product/ERP5/Document/ResourceMeasuresConsistencyConstraint.py @@ -48,13 +48,10 @@ class ResourceMeasuresConsistencyConstraint(ConstraintMixin): PropertySheet.Reference, PropertySheet.ResourceMeasuresConsistencyConstraint) - def checkConsistency(self, obj, fixit=0): + def _checkConsistency(self, obj, fixit=0): """ Check the object's consistency """ - if not self.test(obj): - return [] - error_list = [] portal = obj.getPortalObject() diff --git a/product/ERP5/Document/TradeModelLineCellConsistencyConstraint.py b/product/ERP5/Document/TradeModelLineCellConsistencyConstraint.py index 0ebd35ee4bb5c09410db9917ffbc4b8f77fb8d29..1c37dca91d3bc0329952c99e1c6cae01578dfadc 100644 --- a/product/ERP5/Document/TradeModelLineCellConsistencyConstraint.py +++ b/product/ERP5/Document/TradeModelLineCellConsistencyConstraint.py @@ -47,13 +47,10 @@ class TradeModelLineCellConsistencyConstraint(ConstraintMixin): PropertySheet.Reference, PropertySheet.TradeModelLineCellConsistencyConstraint) - def checkConsistency(self, document, fixit=0): + def _checkConsistency(self, document, fixit=0): """ Check the object's consistency """ - if not self.test(document): - return [] - base_id = self.getBaseId() for cell_coordinates in document.getCellKeyList(base_id=base_id): if document.getCell(base_id=base_id, *cell_coordinates) is None: diff --git a/product/ERP5/Document/TransactionQuantityValueFeasabilityConstraint.py b/product/ERP5/Document/TransactionQuantityValueFeasabilityConstraint.py index 4e4c5c6251d912008f020d8572fcf01928d169c3..304754e7cdac1547c22d2500772d0de60418dfac 100644 --- a/product/ERP5/Document/TransactionQuantityValueFeasabilityConstraint.py +++ b/product/ERP5/Document/TransactionQuantityValueFeasabilityConstraint.py @@ -45,14 +45,11 @@ class TransactionQuantityValueFeasabilityConstraint(ConstraintMixin): PropertySheet.Predicate, PropertySheet.Reference) - def checkConsistency(self, object, fixit=0): + def _checkConsistency(self, object, fixit=0): """ Check if the quantity of the transaction is possible for the source and the destination """ - if not self.test(object): - return [] - errors = [] source_cell = object.getSourceValue() destination_cell = object.getDestinationValue() diff --git a/product/ERP5/Document/TransactionQuantityValueValidityConstraint.py b/product/ERP5/Document/TransactionQuantityValueValidityConstraint.py index d77987a8a8cbcf8ab95254be534a50f1e680af19..a04afa173dc9a90855181c5309028dba37b0bab9 100644 --- a/product/ERP5/Document/TransactionQuantityValueValidityConstraint.py +++ b/product/ERP5/Document/TransactionQuantityValueValidityConstraint.py @@ -42,14 +42,11 @@ class TransactionQuantityValueValidityConstraint(ConstraintMixin): PropertySheet.Predicate, PropertySheet.Reference) - def checkConsistency(self, object, fixit=0): + def _checkConsistency(self, object, fixit=0): """ Check if the quantity of the transaction is greater than the balance of the source. """ - if not self.test(object): - return [] - errors = [] source_cell = object.getSourceValue() diff --git a/product/ERP5Type/Constraint/AttributeBlacklisted.py b/product/ERP5Type/Constraint/AttributeBlacklisted.py index 8b220f45033354e830aefc2e8eb8ff591713af47..b2aace084ece558539c9a70fe4dae861fcea5e41 100644 --- a/product/ERP5Type/Constraint/AttributeBlacklisted.py +++ b/product/ERP5Type/Constraint/AttributeBlacklisted.py @@ -47,14 +47,12 @@ class AttributeBlacklisted(PropertyExistence): message_invalid_attribute_blacklisted = "Attribute ${attribute_name}: "\ "value is blacklisted" - def checkConsistency(self, obj, fixit=0): + def _checkConsistency(self, obj, fixit=0): """Check the object's consistency. We will make sure that each non None constraint_definition is satisfied """ - if not self._checkConstraintCondition(obj): - return [] - errors = PropertyExistence.checkConsistency(self, obj, fixit=fixit) + errors = PropertyExistence._checkConsistency(self, obj, fixit=fixit) for attribute_name, expression_blacklisted_list in self.constraint_definition.items(): message_id = None mapping = dict(attribute_name=attribute_name) diff --git a/product/ERP5Type/Constraint/AttributeEquality.py b/product/ERP5Type/Constraint/AttributeEquality.py index 0134d1c3141f2e89e5925015426a2c56e698533a..e3daf9b9238d61763d0d1f88c88a6b0daf1ef7aa 100644 --- a/product/ERP5Type/Constraint/AttributeEquality.py +++ b/product/ERP5Type/Constraint/AttributeEquality.py @@ -50,14 +50,12 @@ class AttributeEquality(PropertyExistence): message_invalid_attribute_value_fixed = "Attribute ${attribute_name} "\ "value is ${current_value} but should be ${expected_value} (Fixed)" - def checkConsistency(self, obj, fixit=0): + def _checkConsistency(self, obj, fixit=0): """Check the object's consistency. We will make sure that each non None constraint_definition is satisfied (equality) """ - if not self._checkConstraintCondition(obj): - return [] - errors = PropertyExistence.checkConsistency(self, obj, fixit=fixit) + errors = PropertyExistence._checkConsistency(self, obj, fixit=fixit) for attribute_name, expected_value in self.constraint_definition.items(): message_id = None mapping = dict() diff --git a/product/ERP5Type/Constraint/AttributeUnicity.py b/product/ERP5Type/Constraint/AttributeUnicity.py index 0152a326af957f213f5150bb3eefc41adce1bbe9..a434b8c72b381f40d5e1cae769ad6d62a76e1593 100644 --- a/product/ERP5Type/Constraint/AttributeUnicity.py +++ b/product/ERP5Type/Constraint/AttributeUnicity.py @@ -51,15 +51,13 @@ class AttributeUnicity(PropertyExistence): message_invalid_attribute_unicity = "Attribute ${attribute_name} "\ "value is ${value} but should be unique" - def checkConsistency(self, obj, fixit=0): + def _checkConsistency(self, obj, fixit=0): """Check the object's consistency. We will make sure that each non None constraint_definition is satisfied (unicity) This Constraint use portal_catalog """ - if not self._checkConstraintCondition(obj): - return [] - errors = PropertyExistence.checkConsistency(self, obj, fixit=fixit) + errors = PropertyExistence._checkConsistency(self, obj, fixit=fixit) for attribute_name, expression_criterion_dict in self.constraint_definition.items(): message_id = None mapping = dict(attribute_name=attribute_name) diff --git a/product/ERP5Type/Constraint/CategoryAcquiredMembershipState.py b/product/ERP5Type/Constraint/CategoryAcquiredMembershipState.py index 4fb91a20ffc844c7f38cd133f220aef13377b10b..7b94a9569d4c95e9d9a416014783f1688515fc99 100644 --- a/product/ERP5Type/Constraint/CategoryAcquiredMembershipState.py +++ b/product/ERP5Type/Constraint/CategoryAcquiredMembershipState.py @@ -52,11 +52,9 @@ class CategoryAcquiredMembershipState(Constraint): "${workflow_variable} for object ${membership_url} is ${current_state} " \ "which is not in ${valid_state_list}" - def checkConsistency(self, obj, fixit=0): + def _checkConsistency(self, obj, fixit=0): """Check the object's consistency. """ - if not self._checkConstraintCondition(obj): - return [] error_list = [] # Retrieve values inside de PropertySheet (_constraints) base_category = self.constraint_definition['base_category'] diff --git a/product/ERP5Type/Constraint/CategoryExistence.py b/product/ERP5Type/Constraint/CategoryExistence.py index 1cfd982267171ce279e3b5772e995f599fafc5b9..79ef2beadb2ab488568dab1518b9d38af518218c 100644 --- a/product/ERP5Type/Constraint/CategoryExistence.py +++ b/product/ERP5Type/Constraint/CategoryExistence.py @@ -55,11 +55,9 @@ class CategoryExistence(Constraint): return len(obj.getCategoryMembershipList(base_category, portal_type=portal_type)) - def checkConsistency(self, obj, fixit=0): + def _checkConsistency(self, obj, fixit=0): """Check the object's consistency. """ - if not self._checkConstraintCondition(obj): - return [] error_list = [] portal_type = self.constraint_definition.get('portal_type', ()) # For each attribute name, we check if defined diff --git a/product/ERP5Type/Constraint/CategoryMembershipArity.py b/product/ERP5Type/Constraint/CategoryMembershipArity.py index 4eb30350df07591ad1b7bc66902db6a1b9b28bf0..000e6eb612bdb2d9622a5162e7d2dcef7656927b 100644 --- a/product/ERP5Type/Constraint/CategoryMembershipArity.py +++ b/product/ERP5Type/Constraint/CategoryMembershipArity.py @@ -73,14 +73,12 @@ class CategoryMembershipArity(Constraint): return len(obj.getCategoryMembershipList(base_category, portal_type=portal_type)) - def checkConsistency(self, obj, fixit=0): + def _checkConsistency(self, obj, fixit=0): """Check the object's consistency. 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 [] error_list = [] # Retrieve configuration values from PropertySheet (_constraints) base_category = self.constraint_definition['base_category'] diff --git a/product/ERP5Type/Constraint/CategoryMembershipState.py b/product/ERP5Type/Constraint/CategoryMembershipState.py index ba116fb3a5f1b258dcb5028b4dea4032e44e0020..8b08b86952d32034929efd8b22d2e86b4031d14e 100644 --- a/product/ERP5Type/Constraint/CategoryMembershipState.py +++ b/product/ERP5Type/Constraint/CategoryMembershipState.py @@ -51,11 +51,9 @@ class CategoryMembershipState(Constraint): "${workflow_variable} for object ${membership_url} is ${current_state} " \ "which is not in ${valid_state_list}" - def checkConsistency(self, obj, fixit=0): + def _checkConsistency(self, obj, fixit=0): """Check the object's consistency. """ - if not self._checkConstraintCondition(obj): - return [] error_list = [] # Retrieve values inside de PropertySheet (_constraints) base_category = self.constraint_definition['base_category'] diff --git a/product/ERP5Type/Constraint/CategoryRelatedMembershipState.py b/product/ERP5Type/Constraint/CategoryRelatedMembershipState.py index 0053928e6e1eefd74fb922b1fab0c488b25884a4..41de5fee871631cf7dea9f2fec80b9c2ba6deb33 100644 --- a/product/ERP5Type/Constraint/CategoryRelatedMembershipState.py +++ b/product/ERP5Type/Constraint/CategoryRelatedMembershipState.py @@ -51,11 +51,9 @@ class CategoryRelatedMembershipState(CategoryMembershipState): }, """ - def checkConsistency(self, obj, fixit=0): + def _checkConsistency(self, obj, fixit=0): """Check the object's consistency. """ - if not self._checkConstraintCondition(obj): - return [] error_list = [] # Retrieve values inside de PropertySheet (_constraints) base_category = self.constraint_definition['base_category'] diff --git a/product/ERP5Type/Constraint/Constraint.py b/product/ERP5Type/Constraint/Constraint.py index 6621f51bb49fbd9f0d1717ad67128c7721e8c6c4..841bcd4df911db928ff0551ab17ce390c92ccffd 100644 --- a/product/ERP5Type/Constraint/Constraint.py +++ b/product/ERP5Type/Constraint/Constraint.py @@ -103,6 +103,16 @@ class Constraint: return 1 # no condition or a True condition was defined def checkConsistency(self, obj, fixit=0, **kw): + """ + Check the object's consistency. Note that _checkConsistency() + should be overriden in the Constraints rather than this one. + """ + if not self._checkConstraintCondition(obj): + return [] + + return self._checkConsistency(obj, fixit, **kw) + + def _checkConsistency(self, obj, fixit=0, **kw): """ Default method is to return no error. """ diff --git a/product/ERP5Type/Constraint/ContentExistence.py b/product/ERP5Type/Constraint/ContentExistence.py index 40e942f6a48ca6ed4e3d4f097e48ce448500c053..c1450518eca3df364cc9b43da4861ab8c1c6f741 100644 --- a/product/ERP5Type/Constraint/ContentExistence.py +++ b/product/ERP5Type/Constraint/ContentExistence.py @@ -48,27 +48,26 @@ class ContentExistence(Constraint): message_no_subobject_portal_type = "The document does not contain any"\ " subobject of portal portal type ${portal_type}" - def checkConsistency(self, obj, fixit=0): + def _checkConsistency(self, obj, fixit=0): """Checks that object contains a subobject. """ from Products.ERP5Type.Message import Message error_list = [] - if self._checkConstraintCondition(obj): - # Retrieve configuration values from PropertySheet (_constraints) - portal_type = self.constraint_definition.get('portal_type', ()) - if not len(obj.contentValues(portal_type=portal_type)): - # Generate error message - mapping = {} - message_id = 'message_no_subobject' - if portal_type is not (): - message_id = 'message_no_subobject_portal_type' - # XXX maybe this could be factored out - if isinstance(portal_type, basestring): - portal_type = (portal_type, ) - mapping['portal_type'] = str(Message('erp5_ui', ' or ')).join( - [str(Message('erp5_ui', pt)) for pt in portal_type]) - # Add error - error_list.append(self._generateError(obj, - self._getMessage(message_id), mapping)) + # Retrieve configuration values from PropertySheet (_constraints) + portal_type = self.constraint_definition.get('portal_type', ()) + if not len(obj.contentValues(portal_type=portal_type)): + # Generate error message + mapping = {} + message_id = 'message_no_subobject' + if portal_type is not (): + message_id = 'message_no_subobject_portal_type' + # XXX maybe this could be factored out + if isinstance(portal_type, basestring): + portal_type = (portal_type, ) + mapping['portal_type'] = str(Message('erp5_ui', ' or ')).join( + [str(Message('erp5_ui', pt)) for pt in portal_type]) + # Add error + error_list.append(self._generateError(obj, + self._getMessage(message_id), mapping)) return error_list diff --git a/product/ERP5Type/Constraint/PortalTypeClass.py b/product/ERP5Type/Constraint/PortalTypeClass.py index 1c47cc69512cdd0d8c49ba2de58a6215691208bd..dcd87a169310efcc966a9175e89436ebb0382ff8 100644 --- a/product/ERP5Type/Constraint/PortalTypeClass.py +++ b/product/ERP5Type/Constraint/PortalTypeClass.py @@ -60,11 +60,9 @@ class PortalTypeClass(Constraint): " definition. Portal Type class is ${portal_type_class},"\ " document class is ${document_class}" - def checkConsistency(self, obj, fixit=0): + def _checkConsistency(self, obj, fixit=0): """Check the object's consistency. """ - if not self._checkConstraintCondition(obj): - return [] error_list = [] types_tool = getToolByName(obj, 'portal_types') type_info = types_tool._getOb(obj.getPortalType(), None) diff --git a/product/ERP5Type/Constraint/PropertyExistence.py b/product/ERP5Type/Constraint/PropertyExistence.py index 65140060d0e086551024e08bd755c90a186e3bcd..2dad680cc2052a02c364427bf0882a1f2fc2ddca 100644 --- a/product/ERP5Type/Constraint/PropertyExistence.py +++ b/product/ERP5Type/Constraint/PropertyExistence.py @@ -51,11 +51,9 @@ class PropertyExistence(Constraint): message_property_not_set = "Property existence error for property "\ "${property_id}, this property is not defined" - def checkConsistency(self, obj, fixit=0): + def _checkConsistency(self, obj, fixit=0): """Check the object's consistency. """ - if not self._checkConstraintCondition(obj): - return [] error_list = [] # For each attribute name, we check if defined for property_id in self.constraint_definition.keys(): diff --git a/product/ERP5Type/Constraint/PropertyTypeValidity.py b/product/ERP5Type/Constraint/PropertyTypeValidity.py index 5c49d17ed15065365cbc7a7715926376d29b08f7..02b70be32b6edf95d6f5980af81484568e2cb5d3 100644 --- a/product/ERP5Type/Constraint/PropertyTypeValidity.py +++ b/product/ERP5Type/Constraint/PropertyTypeValidity.py @@ -75,12 +75,9 @@ class PropertyTypeValidity(Constraint): " should be of type ${expected_type} but is of type ${actual_type} (Fixed)" - def checkConsistency(self, obj, fixit=0): + def _checkConsistency(self, obj, fixit=0): """Check the object's consistency. """ - if not self._checkConstraintCondition(obj): - return [] - error_list = [] # For each attribute name, we check type for prop in obj.propertyMap(): diff --git a/product/ERP5Type/Constraint/StringAttributeMatch.py b/product/ERP5Type/Constraint/StringAttributeMatch.py index a0ff94b7b3cbeed07df1b3176e4e04dee5d5db90..13f38dc21431da0ca2662d3f346163cbdc8a9009 100644 --- a/product/ERP5Type/Constraint/StringAttributeMatch.py +++ b/product/ERP5Type/Constraint/StringAttributeMatch.py @@ -47,11 +47,11 @@ class StringAttributeMatch(PropertyExistence): message_attribute_does_not_match = "Attribute ${attribute_name} is "\ "${attribute_value} and does not match ${regular_expression}." - def checkConsistency(self, object, fixit=0): + def _checkConsistency(self, object, fixit=0): """Check the object's consistency. Check that each attribute matches the regular expression. """ - error_list = PropertyExistence.checkConsistency( + error_list = PropertyExistence._checkConsistency( self, object, fixit=fixit) if not error_list: for attribute_name, regular_expression in\ diff --git a/product/ERP5Type/Constraint/TALESConstraint.py b/product/ERP5Type/Constraint/TALESConstraint.py index 2f5561906794da6126cd5f00e18173c98836a790..4aa863f51fdc4023507264dcf5c123b985e6249c 100644 --- a/product/ERP5Type/Constraint/TALESConstraint.py +++ b/product/ERP5Type/Constraint/TALESConstraint.py @@ -63,13 +63,11 @@ class TALESConstraint(Constraint): message_expression_error = \ "Error while evaluating expression: ${error_text}" - def checkConsistency(self, obj, fixit=0): + def _checkConsistency(self, obj, fixit=0): """Check the object's consistency. """ # import this later to prevent circular import from Products.ERP5Type.Utils import createExpressionContext - if not self._checkConstraintCondition(obj): - return [] error_list = [] expression_text = self.constraint_definition['expression'] expression = Expression(expression_text) diff --git a/product/ERP5Type/Core/AttributeEqualityConstraint.py b/product/ERP5Type/Core/AttributeEqualityConstraint.py index 6b511a8ad83cd46cc9e7d2a04f887a87a0e9d97d..187380f146ef6fcddbcc6f08fef396b1fe811833 100644 --- a/product/ERP5Type/Core/AttributeEqualityConstraint.py +++ b/product/ERP5Type/Core/AttributeEqualityConstraint.py @@ -66,13 +66,10 @@ class AttributeEqualityConstraint(ConstraintMixin): security.declareProtected(Permissions.AccessContentsInformation, 'checkConsistency') - def checkConsistency(self, obj, fixit=False): + def _checkConsistency(self, obj, fixit=False): """ Check the object's consistency. """ - if not self.test(obj): - return [] - attribute_name = self.getConstraintAttributeName() # If property does not exist, error will be raised by diff --git a/product/ERP5Type/Core/CategoryExistenceConstraint.py b/product/ERP5Type/Core/CategoryExistenceConstraint.py index 40bb07232a4f3ccd6d17a2a77311388b8b6ae9bb..1f82938c2e5631f76ebf4bca8054a7fac7c99fe7 100644 --- a/product/ERP5Type/Core/CategoryExistenceConstraint.py +++ b/product/ERP5Type/Core/CategoryExistenceConstraint.py @@ -59,13 +59,10 @@ class CategoryExistenceConstraint(ConstraintMixin): security.declareProtected(Permissions.AccessContentsInformation, 'checkConsistency') - def checkConsistency(self, obj, fixit=0): + def _checkConsistency(self, obj, fixit=0): """ Check the object's consistency. """ - if not self.test(obj): - return [] - error_list = [] portal_type_list = self.getConstraintPortalTypeList() # For each attribute name, we check if defined diff --git a/product/ERP5Type/Core/CategoryMembershipArityConstraint.py b/product/ERP5Type/Core/CategoryMembershipArityConstraint.py index 66b65d998f280e60f78f73bbfddceda4efc18379..cbe62fc069150c6418a74aa9cdf0cb03d77d262c 100644 --- a/product/ERP5Type/Core/CategoryMembershipArityConstraint.py +++ b/product/ERP5Type/Core/CategoryMembershipArityConstraint.py @@ -65,15 +65,12 @@ class CategoryMembershipArityConstraint(ConstraintMixin): return len(obj.getCategoryMembershipList(base_category_list, portal_type=portal_type_list)) - def checkConsistency(self, obj, fixit=0): + def _checkConsistency(self, obj, fixit=0): """ Check the object's consistency. We are looking at the definition of the constraint where the minimum and the maximum arities are defined, and the list of objects we wants to check the arity for """ - if not self.test(obj): - return [] - # Retrieve configuration values from PropertySheet base_category_list = self.getConstraintBaseCategoryList() min_arity = self.getMinArity() diff --git a/product/ERP5Type/Core/ContentExistenceConstraint.py b/product/ERP5Type/Core/ContentExistenceConstraint.py index 06771b35743a0f8a6a73bff7e1b400aeb6cccede..5298fbf0633113effd5fa71d738e51aa625620c6 100644 --- a/product/ERP5Type/Core/ContentExistenceConstraint.py +++ b/product/ERP5Type/Core/ContentExistenceConstraint.py @@ -62,14 +62,11 @@ class ContentExistenceConstraint(ConstraintMixin): PropertySheet.Reference, PropertySheet.ContentExistenceConstraint) - def checkConsistency(self, obj, fixit=0): + def _checkConsistency(self, obj, fixit=0): """ Checks that object contains at least one subobject and, if a list of Portal Type has been given, check their Portal Types """ - if not self.test(obj): - return [] - portal_type = self._getExpressionValue(obj, self.getConstraintPortalType()) diff --git a/product/ERP5Type/Core/PropertyExistenceConstraint.py b/product/ERP5Type/Core/PropertyExistenceConstraint.py index 5791af3694372b0e4730d2243ea115a14cadab64..98468ad76d664b026aaeb79871cf94ddd1bf4632 100644 --- a/product/ERP5Type/Core/PropertyExistenceConstraint.py +++ b/product/ERP5Type/Core/PropertyExistenceConstraint.py @@ -61,13 +61,10 @@ class PropertyExistenceConstraint(ConstraintMixin): security.declareProtected(Permissions.AccessContentsInformation, 'checkConsistency') - def checkConsistency(self, obj, fixit=0): + def _checkConsistency(self, obj, fixit=0): """ Check the object's consistency. """ - if not self.test(obj): - return [] - error_list = [] # For each attribute name, we check if defined for property_id in self.getConstraintPropertyList(): diff --git a/product/ERP5Type/Core/PropertyTypeValidityConstraint.py b/product/ERP5Type/Core/PropertyTypeValidityConstraint.py index 8a40bc3b739d843d669fb697ce5da2de66dbf66a..4e7dab368015494823be95bec628b1319a2bad7d 100644 --- a/product/ERP5Type/Core/PropertyTypeValidityConstraint.py +++ b/product/ERP5Type/Core/PropertyTypeValidityConstraint.py @@ -68,13 +68,10 @@ class PropertyTypeValidityConstraint(ConstraintMixin): # Properties of type eg. "object" can hold anything _permissive_type_list = ('object', 'data') - def checkConsistency(self, obj, fixit=0): + def _checkConsistency(self, obj, fixit=0): """ Check the object's consistency. """ - if not self.test(obj): - return [] - error_list = [] # For each attribute name, we check type for prop in obj.propertyMap(): diff --git a/product/ERP5Type/Core/TALESConstraint.py b/product/ERP5Type/Core/TALESConstraint.py index 05e7f3f45916c822f01c43d6fa7a714a328c0680..d713b5a119fb749e283d5be26b045164c0ccacf4 100644 --- a/product/ERP5Type/Core/TALESConstraint.py +++ b/product/ERP5Type/Core/TALESConstraint.py @@ -66,14 +66,11 @@ class TALESConstraint(ConstraintMixin): PropertySheet.Reference, PropertySheet.TALESConstraint) - def checkConsistency(self, obj, fixit=0): + def _checkConsistency(self, obj, fixit=0): """ Check that the Expression does not contain an error and is not evaluated to False """ - if not self.test(obj): - return [] - expression_text = self.getExpression() try: diff --git a/product/ERP5Type/mixin/constraint.py b/product/ERP5Type/mixin/constraint.py index 5dbaf52158e573c3cc77dfe715c7334279566f8e..e9529a4584a2a6d59966064d2a2add6b28d5f755 100644 --- a/product/ERP5Type/mixin/constraint.py +++ b/product/ERP5Type/mixin/constraint.py @@ -76,10 +76,13 @@ class ConstraintMixin(Predicate): 'checkConsistency') def checkConsistency(self, obj, fixit=0, **kw): """ - Default method is to return no error. + Check the pre-condition before checking the consistency. + _checkConsistency() must be define in the child class. """ - errors = [] - return errors + if not self.test(obj): + return [] + + return self._checkConsistency(obj, fixit, **kw) security.declareProtected(Permissions.AccessContentsInformation, 'fixConsistency')