[Erp5-report] r21382 - in /erp5/trunk/products/ERP5Type: Base.py tests/testConstraint.py

nobody at svn.erp5.org nobody at svn.erp5.org
Fri Jun 6 15:43:56 CEST 2008


Author: romain
Date: Fri Jun  6 15:43:54 2008
New Revision: 21382

URL: http://svn.erp5.org?rev=21382&view=rev
Log:
Try to guess the type of a newly created local property.

Modified:
    erp5/trunk/products/ERP5Type/Base.py
    erp5/trunk/products/ERP5Type/tests/testConstraint.py

Modified: erp5/trunk/products/ERP5Type/Base.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Base.py?rev=21382&r1=21381&r2=21382&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Base.py (original)
+++ erp5/trunk/products/ERP5Type/Base.py Fri Jun  6 15:43:54 2008
@@ -61,6 +61,7 @@
 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 @@
     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 at nexedi.com

Modified: erp5/trunk/products/ERP5Type/tests/testConstraint.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/tests/testConstraint.py?rev=21382&r1=21381&r2=21382&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/tests/testConstraint.py (original)
+++ erp5/trunk/products/ERP5Type/tests/testConstraint.py Fri Jun  6 15:43:54 2008
@@ -516,7 +516,7 @@
               SetObjectBadTypedProperty \
               CreatePropertyTypeValidity \
               CallCheckConsistency \
-              CheckIfConstraintFailed \
+              CheckIfConstraintSucceeded \
               '
     sequence_list.addSequenceString(sequence_string)
     # Test Constraint with property defined on object
@@ -536,7 +536,7 @@
               SetObjectBadTypedProperty \
               CreatePropertyTypeValidity \
               CallFixConsistency \
-              CheckIfConstraintFailed \
+              CheckIfConstraintSucceeded \
               CallCheckConsistency \
               CheckIfConstraintSucceeded \
               '
@@ -550,7 +550,7 @@
               SetObjectIntLocalProperty \
               CreatePropertyTypeValidity \
               CallFixConsistency \
-              CheckIfConstraintFailed \
+              CheckIfConstraintSucceeded \
               CallCheckConsistency \
               CheckIfConstraintSucceeded \
               '
@@ -1429,8 +1429,7 @@
     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))




More information about the Erp5-report mailing list