web/formfields.py
changeset 6139 f76599a96238
parent 6082 57933567146f
parent 6114 3e1718a2db55
child 6142 8bc6eac1fac1
--- a/web/formfields.py	Thu Aug 12 10:12:52 2010 +0200
+++ b/web/formfields.py	Wed Aug 25 09:43:12 2010 +0200
@@ -860,12 +860,23 @@
     """
     widget = fw.Radio
 
+    def __init__(self, allow_none=False, **kwargs):
+        super(BooleanField, self).__init__(**kwargs)
+        self.allow_none = allow_none
+
     def vocabulary(self, form):
         if self.choices:
             return super(BooleanField, self).vocabulary(form)
+        if self.allow_none:
+            return [('', ''), (form._cw._('yes'), '1'), (form._cw._('no'), '0')]
+        # XXX empty string for 'no' in that case for bw compat
         return [(form._cw._('yes'), '1'), (form._cw._('no'), '')]
 
     def _ensure_correctly_typed(self, form, value):
+        if self.allow_none:
+            if value:
+                return bool(int(value))
+            return None
         return bool(value)