[Checkins] SVN: z3c.form/trunk/ fixed a bug in CollectionSequenceDataConverter calling failures for non-required fields.

Paul Carduner paulcarduner at gmail.com
Sun Feb 15 01:24:29 EST 2009


Log message for revision 96556:
  fixed a bug in CollectionSequenceDataConverter calling failures for non-required fields.

Changed:
  U   z3c.form/trunk/CHANGES.txt
  U   z3c.form/trunk/src/z3c/form/converter.py
  U   z3c.form/trunk/src/z3c/form/converter.txt

-=-
Modified: z3c.form/trunk/CHANGES.txt
===================================================================
--- z3c.form/trunk/CHANGES.txt	2009-02-15 03:53:55 UTC (rev 96555)
+++ z3c.form/trunk/CHANGES.txt	2009-02-15 06:24:29 UTC (rev 96556)
@@ -5,6 +5,10 @@
 Version 2.0.0 (unreleased)
 --------------------------
 
+- Bug: The CollectionSequenceDataConverter no longer throws a
+  "TypeError: 'NoneType' object is not iterable" when passed the value
+  of a non-required field (which in the case of a List field is None).
+
 - Feature: Added support for using sources. Where is was previosly possible to
   use a vocabulary it is now also possible to use a source. This works both
   for basic and contextual sources.

Modified: z3c.form/trunk/src/z3c/form/converter.py
===================================================================
--- z3c.form/trunk/src/z3c/form/converter.py	2009-02-15 03:53:55 UTC (rev 96555)
+++ z3c.form/trunk/src/z3c/form/converter.py	2009-02-15 06:24:29 UTC (rev 96556)
@@ -284,6 +284,8 @@
 
     def toWidgetValue(self, value):
         """Convert from Python bool to HTML representation."""
+        if value is self.field.missing_value:
+            return []
         widget = self.widget
         if widget.terms is None:
             widget.updateTerms()

Modified: z3c.form/trunk/src/z3c/form/converter.txt
===================================================================
--- z3c.form/trunk/src/z3c/form/converter.txt	2009-02-15 03:53:55 UTC (rev 96555)
+++ z3c.form/trunk/src/z3c/form/converter.txt	2009-02-15 06:24:29 UTC (rev 96556)
@@ -665,6 +665,16 @@
   >>> csdv.toWidgetValue([0, 3])
   ['m']
 
+
+Sometimes a field is not required. In those cases, the internal value is the
+missing value of the field. The converter interprets that as no values being
+given:
+
+  >>> genders.missing_value is None
+  True
+  >>> csdv.toWidgetValue(genders.missing_value)
+  []
+
 For some field, like the ``Set``, the collection type is a tuple. Sigh. In
 these cases we use the last entry in the tuple as the type to use:
 



More information about the Checkins mailing list