The "None" placeholder is for a custom error message.  I always look to the 
source code when I have questions like this (which is a frequent occurrence 
for me).  Here is a sample from the source:

class IS_EQUAL_TO(Validator):
    """
    example::

        INPUT(_type='text', _name='password')
        INPUT(_type='text', _name='password2',
              requires=IS_EQUAL_TO(request.vars.password))

    the argument of IS_EQUAL_TO is a string

        >>> IS_EQUAL_TO('aaa')('aaa')
        ('aaa', None)

        >>> IS_EQUAL_TO('aaa')('aab')
        ('aab', 'no match')
    """

    def __init__(self, expression, error_message='No match'):
        self.expression = expression
        self.error_message = error_message

    def __call__(self, value):
        if value == self.expression:
            return (value, None)
        return (value, translate(self.error_message))

As you can see, a custom error message is initialized during the init() 
phase and passed back if there is an error during the call() phase.

-- Joe

On Friday, April 18, 2014 10:24:24 AM UTC-7, [email protected] wrote:
>
> This is a very important question that i would like to complement.
>
> You can use a single custom validator for any kind of parse you want to 
> perform on any particular field, like this.
>
> class process_field():
>     def __init__(self, func):
>         self.func = func
>     def __call__(self, value):
>         return (self.func(value), None)
>
> db.define_table("people",
>     Field("name", "string", length=50, 
> requires=process_field(str.capitalize))
> )
>
> This passes a function to the validator (proccess_field) and outputs the 
> result of the inserted value. This way you dont need to create many 
> validators for each field.
>
> I dont know what None is supposed to be, does anyone knows about it?
>
> Thanks.
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to