Subclass this for conversion fields to custom python objects.
At the least you must override the from_source method.
Original object passed through without modification
Bool is a bit special: Undefined values are be treated as False, by default. This to play nicely with HTML checkbox inputs:
>>> from formalize.core import FormValidator
>>> v = FormValidator()(
... a = Bool()
... )
>>> v.process({})
{'a': False}
You can also tell Bool which values to consider false; anything else will be considered true, and non-presence will be handled as in other types:
>>> from formalize.core import FormValidator
>>> v = FormValidator()(
... a = Bool(falsevalues=['n', 'N'])
... )
>>> v.process({'a': 'yes'})
{'a': True}
>>> v.process({})
Traceback (most recent call last):
...
ValidationError: ValidationError([('a', u'Value empty or invalid')])
Convert to a decimal.Decimal value.
Note that to avoid a name conflict with decimal.Decimal in the stdlib, you may prefer to import this using:
from formalize import Decimal as ValidatorDecimal
Validate and return a python datetime.datetime object
Validate and return a python datetime.date object