[Zope] Question involving passing optional parameters to a zsql method

Jim Penny jpenny at universal-fasteners.com
Tue Oct 19 13:08:26 EDT 2004


On Tue, 19 Oct 2004 18:51:27 +0200
Tino Wildenhain <tino at wildenhain.de> wrote:

> Am Di, den 19.10.2004 schrieb Jim Penny um 17:32:
> > On Tue, 19 Oct 2004 10:19:50 -0500
> > "Laura McCord" <Laura.McCord at doucet-austin.com> wrote:
> ...
> > Suppose you have checkbox with name 'foo'.  In your DTML method,
> > before your ZSQL call, do:
> > 
> > <dtml-call "REQUEST.set('foo', REQUEST.has_key('foo'))>
> > 
> > This will set the variable 'foo' to 0 if the checkbox name is not in
> > the REQUEST (not checked), and 1 if the the checkbox name is in the
> > request(checked).  This is exactly what you want.
> 
> Hm. I doubt that. This would actually set the variable to
> True or False.

Try it.  Of course, it depends on version on python.  As I recall 2.2
and earlier did not have True or False as distinguished values. But the
point is a bit moot, as the SQL adapter is still responsible for
converting True/False to something usable by the SQL layer.


> 
> Solutions: REQUEST.get() can take a default value:
> 
> foo=REQUEST.get('foo',0)
> 
> which will return the actual value or 0

But, you hardly ever want the actual value!  A checkbox creates a name
in the REQUEST, along with a value.  Unless you are very careful, the
value will NOT be something that the SQL adapter can handle as a
representation of true.  Of course, you can write all your forms as

<input type="checkbox" value="1" name="foo">,
but what's the point?

Jim Penny


More information about the Zope mailing list