Re: [web2py] Validator: {Validator1 OR validator2} - Can I get that requires on a Field?

2013-02-19 Thread Alec Taylor
Thanks Bruno, works like a charm. Only caveat is that the error_message is always grabbed from the first validator… On Sat, Feb 16, 2013 at 6:21 AM, Bruno Rocha wrote: > Cool! but it does not allow the transformation. > > class CUSTOM(object): > """ > you can use a function or a lambda >

Re: [web2py] Validator: {Validator1 OR validator2} - Can I get that requires on a Field?

2013-02-15 Thread Bruno Rocha
Cool! but it does not allow the transformation. class CUSTOM(object):"""you can use a function or a lambda to validate or/and transform the field in the way you wantit is the same as "onvalidation" and "onsuccess" form callbacksbut it can be used per field in models or controller l

Re: [web2py] Validator: {Validator1 OR validator2} - Can I get that requires on a Field?

2013-02-15 Thread Massimo Di Pierro
I changed the IS_EXPR validator to allow the same notation suggested for CUSTOM. Can you check? On Thursday, 14 February 2013 21:04:03 UTC-6, rochacbruno wrote: > > It gives me the idea of a CUSTOM validator > > > class CUSTOM(object): > def __init__(self, function): > self.function

Re: [web2py] Validator: {Validator1 OR validator2} - Can I get that requires on a Field?

2013-02-15 Thread Bruno Rocha
Great idea Anthony, CUSTOM can be used in many ways when a builtin validator does not match the requirements. I documented this here: http://rochacbruno.com.br/more-web2py-custom-validators/ @Massimo Can we include at least the CUSTOM in gluon.validators ? -- --- You received this message b

Re: [web2py] Validator: {Validator1 OR validator2} - Can I get that requires on a Field?

2013-02-15 Thread Anthony
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 func

Re: [web2py] Validator: {Validator1 OR validator2} - Can I get that requires on a Field?

2013-02-15 Thread Martin Weissenboeck
Very good ideas! Ok, ALL is not necessary, but it could make a program more readable if there is ANY in teh same program. 2013/2/15 Anthony > I like the idea of including the ANY and CUSTOM validators (we don't need > ALL, though, right? -- that's the default behavior for a list of > validators

Re: [web2py] Validator: {Validator1 OR validator2} - Can I get that requires on a Field?

2013-02-15 Thread Anthony
I like the idea of including the ANY and CUSTOM validators (we don't need ALL, though, right? -- that's the default behavior for a list of validators). 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(

Re: [web2py] Validator: {Validator1 OR validator2} - Can I get that requires on a Field?

2013-02-14 Thread Bruno Rocha
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: d

Re: [web2py] Validator: {Validator1 OR validator2} - Can I get that requires on a Field?

2013-02-14 Thread Bruno Rocha
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 s

Re: [web2py] Validator: {Validator1 OR validator2} - Can I get that requires on a Field?

2013-02-14 Thread Bruno Rocha
I guess the first one is wrong.. to amtch your criteria I think you need this 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

Re: [web2py] Validator: {Validator1 OR validator2} - Can I get that requires on a Field?

2013-02-14 Thread Bruno Rocha
class ANY(object): def __init__(self, validators): self.validators = validators def __call__(self, value): # validates the value against each validator results = [validator(value) for validator in self.validators] # Check if there is an invalid result

[web2py] Validator: {Validator1 OR validator2} - Can I get that requires on a Field?

2013-02-14 Thread Alec Taylor
I am writing in a signup form for users of my site. To signup, they can either use their email address `IS_EMAIL()`; or an outside uid (covered by an `IS_MATCH()`). (it's a 1 field form) One solution to validating the form is to just check the vars in the controller, and have two Fields in the T