Finally, I just testes on the shell

*modules/anyvalidator.py*

class ANY(object):
    def __init__(self, validators):
        self.validators = validators

    def __call__(self, value):
        # validates the value against each validator
        results = [validator(value)[1] for validator in self.validators]
        # check if all validations are invalid
        if all(results):
            # invalid, so return the first error message
            return (value, [result for result in results if result][0])
        else:
            # all valid
            return (value, None)


*models/db.py*

db.table.field.requires = ANY([IS_IN_SET(['a','b']), IS_EMAIL()])

*shell*

In [3]: from anyvalidator import ANY

In [4]: ANY([IS_IN_SET(['a','b']), IS_EMAIL()])('[email protected]')
Out[4]: ('[email protected]', None)

In [5]: ANY([IS_IN_SET(['a','b']), IS_EMAIL()])('me')
Out[5]: ('me', 'value not allowed')

In [6]: ANY([IS_IN_SET(['a','b']), IS_EMAIL()])('a')
Out[6]: ('a', None)

In [7]: ANY([IS_IN_SET(['a','b']), IS_EMAIL()])('b')
Out[7]: ('b', None)

In [8]: ANY([IS_IN_SET(['a','b']), IS_EMAIL()])('foo')
Out[8]: ('foo', 'value not allowed')

In [9]: ANY([IS_IN_SET(['a','b']), IS_EMAIL()])('[email protected]')
Out[9]: ('[email protected]', None)

-- 

--- 
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/groups/opt_out.


Reply via email to