Package gluon :: Module validators :: Class Validator
[hide private]
[frames] | no frames]

Class Validator

source code

object --+
Known Subclasses:

Root for all validators, mainly for documentation purposes.

Validators are classes used to validate input fields (including forms generated from database tables).

Here is an example of using a validator with a FORM:

   INPUT(_name='a', requires=IS_INT_IN_RANGE(0, 10))

Here is an example of how to require a validator for a table field:

   db.define_table('person', SQLField('name'))

Validators are always assigned using the requires attribute of a field. A field can have a single validator or multiple validators. Multiple validators are made part of a list:[IS_NOT_EMPTY(), IS_NOT_IN_DB(db, '')]

Validators are called by the function accepts on a FORM or other HTML helper object that contains a form. They are always called in the order in which they are listed.

Built-in validators have constructors that take the optional argument error message which allows you to change the default error message. Here is an example of a validator on a database table:'Fill this'))

where we have used the translation operator T to allow for internationalization.

Notice that default error messages are not translated.

Instance Methods [hide private]
formatter(self, value)
For some validators returns a formatted version (matching the validator) of value.
source code
__call__(self, value) source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __init__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

formatter(self, value)

source code 

For some validators returns a formatted version (matching the validator) of value. Otherwise just returns the value.