quick fix for typed formfield validation: accept empty string, split
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 09 Feb 2010 19:50:31 +0100
changeset 4528 a51f37efc882
parent 4527 67ab70e98488
child 4529 9b242051f46a
quick fix for typed formfield validation: accept empty string, split
web/formfields.py
--- a/web/formfields.py	Fri Feb 05 17:13:53 2010 +0100
+++ b/web/formfields.py	Tue Feb 09 19:50:31 2010 +0100
@@ -624,6 +624,9 @@
 
     def _ensure_correctly_typed(self, form, value):
         if isinstance(value, basestring):
+            value = value.strip()
+            if not value:
+                return None
             try:
                 return int(value)
             except ValueError:
@@ -655,6 +658,9 @@
 
     def _ensure_correctly_typed(self, form, value):
         if isinstance(value, basestring):
+            value = value.strip()
+            if not value:
+                return None
             try:
                 return float(value)
             except ValueError:
@@ -669,7 +675,7 @@
 
     def format_single_value(self, req, value):
         if value:
-            return ustrftime(value, req.property_value(self.format_prop))
+            return ustrftime(value.strip(), req.property_value(self.format_prop))
         return u''
 
     def render_example(self, req):
@@ -677,6 +683,9 @@
 
     def _ensure_correctly_typed(self, form, value):
         if isinstance(value, basestring):
+            value = value.strip()
+            if not value:
+                return None
             try:
                 value = form._cw.parse_datetime(value, self.etype)
             except ValueError, ex: