formalize.types module API documention

class formalize.types.CustomType(source=None, default=Undefined, message=None, required=True)

Subclass this for conversion fields to custom python objects.

At the least you must override the from_source method.

class formalize.types.PassThrough(source=None, default=Undefined, message=None, required=True)

Original object passed through without modification

class formalize.types.Bool(source=None, falsevalues=None, *args, **kwargs)

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')])
class formalize.types.Decimal(source=None, default=Undefined, message=None, required=True)

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
class formalize.types.DateTime(source=None, default=Undefined, message=None, required=True, format='%d/%m/%y %H:%M:%S')

Validate and return a python datetime.datetime object

class formalize.types.Date(source=None, default=Undefined, message=None, required=True, format='%d/%m/%y')

Validate and return a python datetime.date object

Previous topic

formalize.core module API documention

Next topic

formalize.checks module API documention

This Page