[Zope] Request & has_key
Ausum Studio
ausum_studio at hotmail.com
Wed Apr 21 18:22:31 EDT 2004
----- Original Message -----
From: "Philip Kilner" <phil at xfr.co.uk>
To: "Ausum Studio" <ausum_studio at hotmail.com>
Cc: <zope at zope.org>
Sent: Wednesday, April 21, 2004 4:11 PM
Subject: Re: [Zope] Request & has_key
> Hi Ausum,
>
> Ausum Studio wrote:
> > The only way to pass a variable created as part of one request, to the
> > following one (after you click 'submit' your browser generates a new
one,
> > even though you are calling the same template), is to have it as a form
> > object, maybe as a hidden input tag. You can also perform the same via
> > javascript.
> >
>
> I understand.
>
> I have a page template which is called multiple times, and contains
> conditional behaviour. The first time it is called the script needs to
> identify that it is the first time. The distinguishing characteristic of
> the first pass is the absence of a particular key in the request
> (because no form has been submitted, or script run, to set it - the
> controlling process has not been initialised).
>
> Upon identifying that this is the first pass, a value is set using
> "container.REQUEST.set".
>
> The processes managed by this page (it is generic, and intended to be
> used in a variety of scenarios) are 100% linear - in that at each step
> the transaction may pass or fail, but only a progression forwards
> through a predefined sequence of forms is required. If it fails, the
> form is thrown again to permit the user to supply valid values. If it
> succeeds, a counter is incremented, and the next version is thrown. All
> this works fine.
>
> My only real question is: -
>
> - How can I reliably check for the existence of a given key in the
request?
You use REQUEST.has_key as you already know. Just bear in mind that the
browser will pass a string, not an integer. So your previous sentences
should need to look like this:
if req.has_key('job_step'):
if req.job_step == '1': #
do that...
else:
do the other...
.........
Zope properties machinery doesn't need this as far as you provide a compound
value like 1:int for the variable name 'job_step'. But that doesn't work in
custom created form validation.
Ausum
> Cheers,
>
> PhilK
>
>
More information about the Zope
mailing list