From: <sub...@co...> - 2005-05-25 15:24:46
|
Author: ianb Date: 2005-05-25 15:24:39 +0000 (Wed, 25 May 2005) New Revision: 799 Modified: FormEncode/trunk/formencode/validators.py Log: Added bool validator from Justin Azoff Modified: FormEncode/trunk/formencode/validators.py =================================================================== --- FormEncode/trunk/formencode/validators.py 2005-05-25 15:23:05 UTC (rev 798) +++ FormEncode/trunk/formencode/validators.py 2005-05-25 15:24:39 UTC (rev 799) @@ -718,8 +718,31 @@ self.message('future', state, date=date_formatted), value, state) - +class Bool(FancyValidator): + + """ + Always Valid, returns True or False based on the value and the + existance of the value. + + Examples:: + + >>> Bool.to_python(0) + False + >>> Bool.to_python(1) + True + >>> Bool.to_python('') + False + >>> Bool.to_python(None) + False + """ + + if_missing = False + + def _to_python(self, value, state): + return bool(value) + _from_python = _to_python + class Int(FancyValidator): """ |