[Zope3-checkins] SVN: Zope3/trunk/ Issue 572, http://www.zope.org/Collectors/Zope3-dev/572

Jim Fulton jim at zope.com
Sun Jul 16 11:18:10 EDT 2006


Log message for revision 69147:
  Issue 572, http://www.zope.org/Collectors/Zope3-dev/572
  
  Fixed bug in Dict field binding, adding support for binding key and
  value types.
  

Changed:
  U   Zope3/trunk/doc/CHANGES.txt
  U   Zope3/trunk/src/zope/schema/_field.py
  U   Zope3/trunk/src/zope/schema/tests/test_dictfield.py

-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt	2006-07-16 15:18:06 UTC (rev 69146)
+++ Zope3/trunk/doc/CHANGES.txt	2006-07-16 15:18:09 UTC (rev 69147)
@@ -16,7 +16,10 @@
 
     Bug fixes
 
-      - Fixed issue 572: The icon directive title attribute wasn't implemented.
+      - Fixed issue 572: Dict fields with key_type or value_type set
+        didn't handle binding correctly.
+      
+      - Fixed issue 576: The icon directive title attribute wasn't implemented.
 
       - TAL interpreter didn't translate i18n Messages when inserted
         as structure;

Modified: Zope3/trunk/src/zope/schema/_field.py
===================================================================
--- Zope3/trunk/src/zope/schema/_field.py	2006-07-16 15:18:06 UTC (rev 69146)
+++ Zope3/trunk/src/zope/schema/_field.py	2006-07-16 15:18:09 UTC (rev 69147)
@@ -466,7 +466,18 @@
         finally:
             errors = None
 
+    def bind(self, object):
+        """See zope.schema._bootstrapinterfaces.IField."""
+        clone = super(Dict, self).bind(object)
+        # binding value_type is necessary for choices with named vocabularies,
+        # and possibly also for other fields.
+        if clone.key_type is not None:
+           clone.key_type = clone.key_type.bind(object)
+        if clone.value_type is not None:
+           clone.value_type = clone.value_type.bind(object)
+        return clone
 
+
 _isuri = re.compile(
     r"[a-zA-z0-9+.-]+:"   # scheme
     r"\S*$"               # non space (should be pickier)

Modified: Zope3/trunk/src/zope/schema/tests/test_dictfield.py
===================================================================
--- Zope3/trunk/src/zope/schema/tests/test_dictfield.py	2006-07-16 15:18:06 UTC (rev 69146)
+++ Zope3/trunk/src/zope/schema/tests/test_dictfield.py	2006-07-16 15:18:09 UTC (rev 69147)
@@ -100,6 +100,24 @@
         self.assertRaises(WrongContainedType, field.validate, {(): 'a'} )
 
 
+    def test_bind_binds_key_and_value_types(self):
+        field = self._Field_Factory(
+            __name__ = 'x',
+            title=u'Not required field', description=u'',
+            readonly=False, required=False,
+            key_type=Int(),
+            value_type=Int(),
+            )
+
+        class C(object):
+            x=None
+
+        c = C()
+        field2 = field.bind(c)
+
+        self.assertEqual(field2.key_type.context, c)
+        self.assertEqual(field2.value_type.context, c)
+
 def test_suite():
     return makeSuite(DictTest)
 



More information about the Zope3-Checkins mailing list