Matt Wilson schrieb:
> So, that validate decorator works fine except when an incoming value
> is None.  Despite what the form encode docs say, None is not converted
> into an empty list.
> 
> But I'm probably doing something wrong.  I usually am.  Here's my
> code:
> 
>     @validate(validators={'a':validators.ForEach(validators.Int(),
> convert_to_list=True),
>                           'b':validators.ForEach(validators.Int(),
> convert_to_list=True)})
>     @expose()
>     def f(self, a, b):
>         log.debug("a is %s." % a)
>         log.debug("b is %s." % b)
>         return dict(a=a, b=b)
> 
> When I hit my app with this GET: http://sprout/f?a=1&a=2&b=
> 
> This is what I see in my logs:
> 
> 2008-02-21 15:25:03,649 controllers DEBUG a is [1, 2].
> 2008-02-21 15:25:03,650 controllers DEBUG b is None.
> 
> And this is what I get in my browser:
> 
> {"a": [1, 2], "b": null, "tg_flash": null}
> 
> What silly mistake am I making this time?

How about

def f(self, a=[], b=[])


Just a guess though. To be brutally honest I'm not sure if there even is 
a validator invoked in case of no value being present at all. IF so, 
you could of course create your own ForEach-validator that just does 
this, overloading the _to_python-method (or whichever is needed, but I 
guess that's the one) to return an empty list if the 
super-implementation doesn't.

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
-~----------~----~----~----~------~----~------~--~---

Reply via email to