Commit d6a5d3e3 authored by Romain Courteaud's avatar Romain Courteaud

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
parent 84ba1a9f
...@@ -61,6 +61,7 @@ from Products.ERP5Type.Cache import CachingMethod, clearCache, getReadOnlyTransa ...@@ -61,6 +61,7 @@ from Products.ERP5Type.Cache import CachingMethod, clearCache, getReadOnlyTransa
from Accessor import WorkflowState from Accessor import WorkflowState
from Products.ERP5Type.Log import log as unrestrictedLog from Products.ERP5Type.Log import log as unrestrictedLog
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
from Products.ERP5Type.Accessor.TypeDefinition import type_definition
from ZopePatch import ERP5PropertyManager from ZopePatch import ERP5PropertyManager
from CopySupport import CopyContainer, CopyError,\ from CopySupport import CopyContainer, CopyError,\
...@@ -1426,7 +1427,15 @@ class Base( CopyContainer, ...@@ -1426,7 +1427,15 @@ class Base( CopyContainer,
if ERP5PropertyManager.hasProperty(self,key): if ERP5PropertyManager.hasProperty(self,key):
ERP5PropertyManager._updateProperty(self, key, value) ERP5PropertyManager._updateProperty(self, key, value)
else: 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 # This should not be there, because this ignore all checks made by
# the PropertyManager. If there is problems, please complain to # the PropertyManager. If there is problems, please complain to
# seb@nexedi.com # seb@nexedi.com
......
...@@ -516,7 +516,7 @@ class TestConstraint(PropertySheetTestCase): ...@@ -516,7 +516,7 @@ class TestConstraint(PropertySheetTestCase):
SetObjectBadTypedProperty \ SetObjectBadTypedProperty \
CreatePropertyTypeValidity \ CreatePropertyTypeValidity \
CallCheckConsistency \ CallCheckConsistency \
CheckIfConstraintFailed \ CheckIfConstraintSucceeded \
' '
sequence_list.addSequenceString(sequence_string) sequence_list.addSequenceString(sequence_string)
# Test Constraint with property defined on object # Test Constraint with property defined on object
...@@ -536,7 +536,7 @@ class TestConstraint(PropertySheetTestCase): ...@@ -536,7 +536,7 @@ class TestConstraint(PropertySheetTestCase):
SetObjectBadTypedProperty \ SetObjectBadTypedProperty \
CreatePropertyTypeValidity \ CreatePropertyTypeValidity \
CallFixConsistency \ CallFixConsistency \
CheckIfConstraintFailed \ CheckIfConstraintSucceeded \
CallCheckConsistency \ CallCheckConsistency \
CheckIfConstraintSucceeded \ CheckIfConstraintSucceeded \
' '
...@@ -550,7 +550,7 @@ class TestConstraint(PropertySheetTestCase): ...@@ -550,7 +550,7 @@ class TestConstraint(PropertySheetTestCase):
SetObjectIntLocalProperty \ SetObjectIntLocalProperty \
CreatePropertyTypeValidity \ CreatePropertyTypeValidity \
CallFixConsistency \ CallFixConsistency \
CheckIfConstraintFailed \ CheckIfConstraintSucceeded \
CallCheckConsistency \ CallCheckConsistency \
CheckIfConstraintSucceeded \ CheckIfConstraintSucceeded \
' '
...@@ -1430,7 +1430,6 @@ class TestConstraint(PropertySheetTestCase): ...@@ -1430,7 +1430,6 @@ class TestConstraint(PropertySheetTestCase):
self.assertEquals('Attribute title does not match', self.assertEquals('Attribute title does not match',
str(message.getTranslatedMessage())) str(message.getTranslatedMessage()))
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestConstraint)) suite.addTest(unittest.makeSuite(TestConstraint))
......
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