[Zope] Request & has_key

Matt Hamilton matth at netsight.co.uk
Wed Apr 21 15:15:02 EDT 2004


Philip Kilner wrote:

> 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!

Phil,
   Ummm... I'm still not quite clear what you are trying to achieve 
above.  From what I gather it is like some kind of state machine and you 
want to move from page to page depending on the state, right?  Well you 
do a container.REQUEST.set at the end.  REQUEST shoudl come from 
context, not from container.  Also, what is the point in setting it? 
The REQUEST object is different for each individual HTTP request, it 
will not persist between requests.  In order to do this you should be 
setting and checking the data in REQUEST.SESSION instead.

-Matt

-- 
Matt Hamilton                                       matth at netsight.co.uk
Netsight Internet Solutions, Ltd.        Business Vision on the Internet
http://www.netsight.co.uk                             +44 (0)117 9090901
Web Design | Zope/Plone Development & Consulting | Co-location | Hosting



More information about the Zope mailing list