[Zope] Variables: accessing them across several pages

Chris Kratz chris.kratz@vistashare.com
Fri, 10 Jan 2003 09:24:57 -0500


Matt,

Here are several solutions that might work for you that we have used in 
various situations.  There may be others that work better.

1. Use the session object provided by zope.  Any variables you place in the 
session will be available for subsequent requests from that browser.  Session 
variables are accessible via python and dtml.

2. A less elegant solution, but nonetheless will work is to encode those items 
you need in your second run from the first form as hidden variables in your 
second form.  Make sense?  Basically, you store and forward in the html.

3. Another solution is to use an external dbms such as mysql or postgres or 
even the ZODB to "store" those variables for later retrieval.  But in effect 
you are recreating sessioning and you might as well use 1 unless you have 
special needs.

The solution you choose is probably going to be somewhat dependant on your 
problem as well as what you are most comfortable with.  Probably from your 
description, you will want to use session variables.  Basically, your work 
flow would look like this...

1. Form 1 in html to gather data
2. expy1 does calculations, saves form1 variables in SESSION, generates table 
and form 2
3. Form2 submits to internalpy1 which reads variables from Form1 stored in the  
SESSION and then using that and variables from form2 to do final 
calculations.

Some things to remember about sessioning and the web.  Remember people store 
bookmarks, etc, so you will probably have to deal with the fact that someone 
might jump to form2 without ever visiting form1 ie do things out of order.  
The way we handle that is to redirect to Form1 if required items do not exist 
when requesting Form2.  Hope that helps.

Good luck,

-Chris

On Thursday 09 January 2003 05:40 pm, Redding, Matthew wrote:
> Hi Zope Gurus,
>
> I have been converting an environmental model to
> run as a series of forms on the web.  Zope and python seem so far
> like the correct tool to be using.
>
> Something is really bamboozling me.
> I see that DTML variables can be accessed from DTML document to
> document.
> I see that there are such things as session variables. I have read about
> REQUEST and RESPONSE in the passing of parameters to called python
> scripts and
> external methods....I have this one working.
>
> But I cannot get my brain around the following:
> 1.  I output a form to the web (HTML in this case; lets call it
> "form1").  It collects several values,
> that are submitted to an external python method.
> 2.  External python method "expy1", does some calculations, returns a
> table of values to the web, with a link
> to a subsequent form, "Form2".
> 3.  Submission of "Form2" passes several values to a python script
> "internalpy1".
> 4.   ***Now this is the problem....how can "internalpy1" access the
> values collected in "form1"???  If I use DTML
> for "form1" instead of html, can I make variables persist easier?
>
> It seems that to publish any page to the web from a python script, is to
> halt the python script, since it
> must use it's return to do this...is this correct?
>
> I would **really** appreciate your help with this problem, though it is
> a total newbie issue, I know.
> It has chewed up about four frustrating evenings so far.
>
>
> Thanks for any advice you can offer.
>
> Matt Redding
>
> ********************************DISCLAIMER****************************
> The information contained in the above e-mail message or messages
> (which includes any attachments) is confidential and may be legally
> privileged.  It is intended only for the use of the person or entity
> to which it is addressed.  If you are not the addressee any form of
> disclosure, copying, modification, distribution or any action taken
> or omitted in reliance on the information is unauthorised.  Opinions
> contained in the message(s) do not necessarily reflect the opinions
> of the Queensland Government and its authorities.  If you received
> this communication in error, please notify the sender immediately and
> delete it from your computer system network.
>
> _______________________________________________
> 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 )