[Zope] boolean weirdness

Casey Duncan casey@zope.com
Thu, 2 May 2002 16:08:33 -0400


I think the problem is that the string "0" is not a false value. Both "0"=
 and=20
"1" are true values. All non-empty strings are true in Python.

Generally you would use integer values in a boolean. The integer 0 is ind=
eed=20
considered false. From a web form, you can use marshalling to make the va=
lue=20
into an integer such as:

<input type=3D"radio" name=3D"mybool:int" value=3D"1" />True
<input type=3D"radio" name=3D"mybool:int" value=3D"0" />False

See: http://www.zope.org/Members/Zen/howto/FormVariableTypes
for more details on marshalling. Its very useful.

Alternately, you could use an empty string as a false value.

hth,

Casey

On Thursday 02 May 2002 03:36 pm, vsbabu@vsbabu.org allegedly wrote:
> Hi,
>=20
> We've a ZClass in which there is a property fund_size called boolean.
>=20
> We had to use a radio group in the form like fund_size:boolean and valu=
es as=20
1 and 0 for true and false.
>=20
> However, when we had to retrieve it for pre-checking the radio group=20
according to the value in the property sheet, after some trial and error =
we=20
found that=20
> <dtml-if "fund_size=3D=3D'1'"> works instead of <dtml-if fund_size> as =
would've=20
expected due to "boolean" property.
>=20
> Took some time to get to the string  comparison...
>=20
> $.02
>=20
>=20
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -=20
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )
>=20