Diez -- So, if I understand you right, I can add this on top of my
controller method and be done:
@validate(validators{'a':validators.ForEach(validators.Int(),
convert_to_list=True),
'b':validators.ForEach(validators.Int(), convert_to_list=True)})
def f(a, b):
I've tried this out, and it seems to work fine. a and b are both
converted into lists of integers.
Thanks!
On Feb 21, 2:22 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote:
> Matt Wilson schrieb:
>
> > I have code like this in a lot of controllers:
>
> > def f(a, b):
>
> > # Make sure that a is a list.
> > if not isinstance(a, list):
> > a = [a]
>
> > for x in a:
> > ....
>
> > I have to make sure that a is a list, not a string, before I iterate
> > over it.
>
> Use a proper validator:
>
> validator=validators.ForEach(validators.Int(), convert_to_list=True)
>
> Diez
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---