Maybe the custom validator could also allow for transformations:
class CUSTOM(object):
def __init__(self, validate=lambda value: None, transform=lambda value:value
):
self.validate = validate
self.transform = transform
def __call__(self, value):
# the validate function should return the error_message or None
return(self.transform(value), self.validate(value))
Anthony
On Thursday, February 14, 2013 10:04:03 PM UTC-5, rochacbruno wrote:
>
> It gives me the idea of a CUSTOM validator
>
>
> class CUSTOM(object):
> def __init__(self, function):
> self.function = function
>
> def __call__(self, value):
> # the function should return the error_message or None
> return(value, self.function(value))
>
>
> So the use should be:
>
> def my_validator_function(value):
> # do anything
> return "error message" or None
>
> db.table.field.requires = CUSTOM(my_validator_function)
>
> So, it works the same as onvalidation but can be applied in models.
>
--
---
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.