From d6a5d3e3b10c99debfbbb46e145e7bc75ca6bb3f Mon Sep 17 00:00:00 2001 From: Romain Courteaud <romain@nexedi.com> Date: Fri, 6 Jun 2008 13:43:54 +0000 Subject: [PATCH] Try to guess the type of a newly created local property. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@21382 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5Type/Base.py | 11 ++++++++++- product/ERP5Type/tests/testConstraint.py | 9 ++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/product/ERP5Type/Base.py b/product/ERP5Type/Base.py index c97aee1016..791dcf34c3 100644 --- a/product/ERP5Type/Base.py +++ b/product/ERP5Type/Base.py @@ -61,6 +61,7 @@ from Products.ERP5Type.Cache import CachingMethod, clearCache, getReadOnlyTransa from Accessor import WorkflowState from Products.ERP5Type.Log import log as unrestrictedLog from Products.ERP5Type.TransactionalVariable import getTransactionalVariable +from Products.ERP5Type.Accessor.TypeDefinition import type_definition from ZopePatch import ERP5PropertyManager from CopySupport import CopyContainer, CopyError,\ @@ -1426,7 +1427,15 @@ class Base( CopyContainer, if ERP5PropertyManager.hasProperty(self,key): ERP5PropertyManager._updateProperty(self, key, value) else: - ERP5PropertyManager._setProperty(self, key, value, type=type) + # Try to guess the type definition of this non defined property + for type_name, type_dict in type_definition.items(): + # XXX type parameter name is bad, because it's a builtin function of + # python + if isinstance(value, __builtins__['type'](type_dict.get('default'))): + type = type_name + break + ERP5PropertyManager._setProperty(self, key, value, + type=type) # This should not be there, because this ignore all checks made by # the PropertyManager. If there is problems, please complain to # seb@nexedi.com diff --git a/product/ERP5Type/tests/testConstraint.py b/product/ERP5Type/tests/testConstraint.py index 7fd7f85fe3..2427054f07 100644 --- a/product/ERP5Type/tests/testConstraint.py +++ b/product/ERP5Type/tests/testConstraint.py @@ -516,7 +516,7 @@ class TestConstraint(PropertySheetTestCase): SetObjectBadTypedProperty \ CreatePropertyTypeValidity \ CallCheckConsistency \ - CheckIfConstraintFailed \ + CheckIfConstraintSucceeded \ ' sequence_list.addSequenceString(sequence_string) # Test Constraint with property defined on object @@ -536,7 +536,7 @@ class TestConstraint(PropertySheetTestCase): SetObjectBadTypedProperty \ CreatePropertyTypeValidity \ CallFixConsistency \ - CheckIfConstraintFailed \ + CheckIfConstraintSucceeded \ CallCheckConsistency \ CheckIfConstraintSucceeded \ ' @@ -550,7 +550,7 @@ class TestConstraint(PropertySheetTestCase): SetObjectIntLocalProperty \ CreatePropertyTypeValidity \ CallFixConsistency \ - CheckIfConstraintFailed \ + CheckIfConstraintSucceeded \ CallCheckConsistency \ CheckIfConstraintSucceeded \ ' @@ -1429,8 +1429,7 @@ class TestConstraint(PropertySheetTestCase): message = consistency_message_list[0] self.assertEquals('Attribute title does not match', str(message.getTranslatedMessage())) - - + def test_suite(): suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(TestConstraint)) -- 2.30.9