W-Mark Kubacki <[EMAIL PROTECTED]> writes:
> Hi group,
>
> I cannot figure out where the bug is. The Bool-validator seems to be
> always evaluating to True.
>
> JSON request sends these values:
> {'id': value, 'is_business': false})
> In the controller, the validators are set this way:
> @tg.validate(validators={'id': validators.Int(),
> 'is_business': validators.Bool()})
> def add(id, is_business, tg_errors=None):
> print is_business
> ...
>
> I expect that "False" is printed out, but "True" is it actually. The
> same happens, if I let is_business be 0 in the JSON request -
> interestingly, Bool.to_python(0) returns "False" on the command line.
>
> Did I hit a bug?
Nope. The validator uses the same rules as Python itself, so if one
thing evaluates to True in Python it will be True for the validator.
Also remember that everything you get from the web is a string:
>>> from turbogears.validators import Bool
>>> v = Bool()
>>> v.to_python(0)
False
>>> v.to_python("0")
True
>>> v.to_python('')
False
>>>
Be seeing you,
--
Jorge Godoy <[EMAIL PROTECTED]>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---