[Zope] Boolean properties ( Zope 2.5)

Eron Lloyd elloyd@lancaster.lib.pa.us
04 Sep 2002 13:04:49 -0400


Ahh, yes, what was I thinking ;-)?! Sometimes it's easy to forget that
Zope 2.x isn't very "Pythonic" in places. Ok, so if you set a property
"bool", you can test it like this just fine:

if context.bool:
    print "true"
else:
    print "false"
return printed

If you'd like to poll the property in a form from DTML, try this:

<dtml-if bool>
    <input type="checkbox" name="fooBool" checked />
<dtml-else?
    <input type="checkbox" name="fooBool" />
</dtml-if>

So...you won't know what the actual value of a boolean property will be,
and it doesn't seem to be "on", either. I hope this answers your
question...anyone care to explain how PropertyManager handles boolean
objects?

Cheers,

Eron

On Wed, 2002-09-04 at 11:50, Lennart Regebro wrote:
> From: "Eron Lloyd" <elloyd@lancaster.lib.pa.us>
> > Like Python < 2.2.1, boolean values return integer types 1 (true) or 0
> > (false). In the future, Python will provide boolean objects True and
> > False. So in a Python script:
> >
> > if propertyValue == 1:
> >     doSomething()
> > else:
> >     cancelAction()
> 
> Yeah, but Zope's boolean properties are not necessarily a Python boolean
> value.
> They can be set to basically anything. You use them like this:
> 
> > if propertyValue:
> >     doSomething()
> > else:
> >     cancelAction()
> 
> The "== 1" part will just make the whole thing fail even when the property
> box is checked. I think the default "on" value is "on". :-)
> 
> 
> 
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - 
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )
> ---
> [This E-mail scanned for viruses by Declude Virus]
> 
> 
-- 
Eron Lloyd
Technology Coordinator
Lancaster County Library
elloyd@lancaster.lib.pa.us
Phone: 717-239-2116
Fax: 717-394-3083

---
[This E-mail scanned for viruses by Declude Virus]