[Checkins] SVN: z3c.form/branches/shane-backport/ Created a branch for backporting bugfixes to the stable version of z3c.form, and backported:
Shane Hathaway
shane at hathawaymix.org
Sat Mar 14 13:47:46 EDT 2009
Log message for revision 98106:
Created a branch for backporting bugfixes to the stable version of z3c.form, and backported:
- Bugfix: The `SequenceDataConverter` and `CollectionSequenceDataConverter`
converter classes now ignore values that are not present in the terms when
converting to a widget value.
Changed:
A z3c.form/branches/shane-backport/
U z3c.form/branches/shane-backport/CHANGES.txt
U z3c.form/branches/shane-backport/src/z3c/form/converter.py
U z3c.form/branches/shane-backport/src/z3c/form/converter.txt
-=-
Modified: z3c.form/branches/shane-backport/CHANGES.txt
===================================================================
--- z3c.form/tags/1.9.0/CHANGES.txt 2009-03-12 17:41:21 UTC (rev 98008)
+++ z3c.form/branches/shane-backport/CHANGES.txt 2009-03-14 17:47:46 UTC (rev 98106)
@@ -2,6 +2,14 @@
CHANGES
=======
+Version 1.9.1 (unreleased)
+--------------------------
+
+- Bugfix: The `SequenceDataConverter` and `CollectionSequenceDataConverter`
+ converter classes now ignore values that are not present in the terms when
+ converting to a widget value.
+
+
Version 1.9.0 (2008-08-26)
--------------------------
Modified: z3c.form/branches/shane-backport/src/z3c/form/converter.py
===================================================================
--- z3c.form/tags/1.9.0/src/z3c/form/converter.py 2009-03-12 17:41:21 UTC (rev 98008)
+++ z3c.form/branches/shane-backport/src/z3c/form/converter.py 2009-03-14 17:47:46 UTC (rev 98106)
@@ -255,7 +255,11 @@
return []
# Look up the term in the terms
terms = widget.updateTerms()
- return [terms.getTerm(value).token]
+ try:
+ return [terms.getTerm(value).token]
+ except LookupError, err:
+ # Swallow lookup errors, in case the options changed.
+ return []
def toFieldValue(self, value):
"""See interfaces.IDataConverter"""
@@ -277,7 +281,14 @@
widget = self.widget
if widget.terms is None:
widget.updateTerms()
- return [widget.terms.getTerm(entry).token for entry in value]
+ values = []
+ for entry in value:
+ try:
+ values.append(widget.terms.getTerm(entry).token)
+ except LookupError, err:
+ # Swallow lookup errors, in case the options changed.
+ pass
+ return values
def toFieldValue(self, value):
"""See interfaces.IDataConverter"""
Modified: z3c.form/branches/shane-backport/src/z3c/form/converter.txt
===================================================================
--- z3c.form/tags/1.9.0/src/z3c/form/converter.txt 2009-03-12 17:41:21 UTC (rev 98008)
+++ z3c.form/branches/shane-backport/src/z3c/form/converter.txt 2009-03-14 17:47:46 UTC (rev 98106)
@@ -507,7 +507,7 @@
>>> sdv.toFieldValue(['m'])
0
-Sometimes a field is not required. In those cases, the internalvalue is the
+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 value being
selected:
@@ -516,6 +516,12 @@
>>> sdv.toWidgetValue(gender.missing_value)
[]
+If the internal value is not a valid item in the terms, it is treated as
+missing:
+
+ >>> sdv.toWidgetValue(object())
+ []
+
If "no value" has been specified in the widget, the missing value
of the field is returned:
@@ -561,6 +567,19 @@
>>> csdv.toFieldValue(['m'])
[0]
+Of course, a collection field can also have multiple values:
+
+ >>> csdv.toWidgetValue([0, 1])
+ ['m', 'f']
+
+ >>> csdv.toFieldValue(['m', 'f'])
+ [0, 1]
+
+If any of the values are not a valid choice, they are simply ignored:
+
+ >>> csdv.toWidgetValue([0, 3])
+ ['m']
+
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