web/formfields.py
branchstable
changeset 6114 3e1718a2db55
parent 5955 67dfe437bf25
child 6139 f76599a96238
child 6218 d37428222a63
--- a/web/formfields.py	Tue Aug 17 15:22:04 2010 +0200
+++ b/web/formfields.py	Tue Aug 17 15:22:57 2010 +0200
@@ -854,12 +854,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)