[Zope] Request & has_key
Jim Kutter
jim at ebizq.net
Wed Apr 21 15:31:00 EDT 2004
I would simply do the following
job_step = int(request.get('job_step', 1))
-jim
-----Original Message-----
From: Philip Kilner [mailto:phil at xfr.co.uk]
Sent: Wednesday, April 21, 2004 2:57 PM
To: zope at zope.org
Subject: [Zope] Request & has_key
Hi List,
I'm having problems with testing for the existence of a key in my
request. I've had similar problems in the past, and asked the list in
the past, but always managed to fumble my way out of them - now I seem
to be 100% stuck!
I'm working on a page template which calls a python script. This script
needs to: -
- Test for the existence of a counter called "job_step".
- If it does not exist, initialise it as one (it's an integer).
- If it does exist, perform conditional tasks based on it's value.
My script reads, in part: -
req = context.REQUEST
if req.has_key('job_step'):
if req.job_step == 1:
do that...
else:
do the other...
else:
container.REQUEST.set('job_step', 1)
do this...
...and that's where my problem lies - the test /always/ fails!
If I throw the whole request into the page template, I can see that the
key "job_step" is listed, with a value of one. Subsequently, a second
script called by the same template increments it to two, which I can
also see, if I comment out the line which sets it to one - but when the
whole page is thrown for "step 2", the test fails and the value is reset
to one.
So: -
- Can anyone help me understand what I'm doing wrong?
- I've been advised in the past that "REQUEST", although it "acts" like
a dictionary is not actually a dictionary. Is this so?
- Is there a way of testing that "req" is a dictionary?
- If it isn't, shouldn't "has_key" barf?
This feels like a basic, stupid, question, but I'm stuck and - apart
from reminding me that I've been here before, Google is apparently /not/
my friend today...
TIA
Cheers,
PhilK
_______________________________________________
Zope maillist - Zope at zope.org
http://mail.zope.org/mailman/listinfo/zope
** No cross posts or HTML encoding! **
(Related lists -
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope-dev )
More information about the Zope
mailing list