[Checkins] SVN: z3c.form/trunk/src/z3c/form/converter. Fix the
converter when the incoming value is an mepty
Stephan Richter
srichter at cosmos.phy.tufts.edu
Mon Jun 4 02:19:19 EDT 2007
Log message for revision 76275:
Fix the converter when the incoming value is an mepty
string. An empty string really means that we have no value
and it is thus missing. At least in the UI we cannot easily
separate the two.
Changed:
U z3c.form/trunk/src/z3c/form/converter.py
U z3c.form/trunk/src/z3c/form/converter.txt
-=-
Modified: z3c.form/trunk/src/z3c/form/converter.py
===================================================================
--- z3c.form/trunk/src/z3c/form/converter.py 2007-06-04 05:50:34 UTC (rev 76274)
+++ z3c.form/trunk/src/z3c/form/converter.py 2007-06-04 06:19:18 UTC (rev 76275)
@@ -44,6 +44,8 @@
def toFieldValue(self, value):
"""See interfaces.IDataConverter"""
+ if value == u'':
+ return self.field.missing_value
return self.field.fromUnicode(value)
def __repr__(self):
Modified: z3c.form/trunk/src/z3c/form/converter.txt
===================================================================
--- z3c.form/trunk/src/z3c/form/converter.txt 2007-06-04 05:50:34 UTC (rev 76274)
+++ z3c.form/trunk/src/z3c/form/converter.txt 2007-06-04 06:19:18 UTC (rev 76275)
@@ -42,6 +42,13 @@
>>> conv.toFieldValue('34')
34
+An empty string means simply that the value is missing and the missing value
+of the field is returned:
+
+ >>> age.missing_value = -1
+ >>> conv.toFieldValue('')
+ -1
+
Of course, trying to convert a non-integer string representation fails in a
conversion error:
More information about the Checkins
mailing list