[Zope] I am so lost.

Dylan Reinhardt zope at dylanreinhardt.com
Fri Sep 26 00:29:49 EDT 2003


On Thu, 2003-09-25 at 18:58, Bob Gailer wrote:

> Even trying to grok some simple concepts. e.g. one can specify parameters 
> on a Script (Python) object, but nothing I can find explains how these 
> parameters get values. 


When Zope receives a request a lot of information about that request is
bundled up into the REQUEST object.  This information includes any
variables that were provided by the client, whether through GET or POST.

To get an idea of what kind of information the REQUEST object is
carrying around, create a Python Script called my_test that contains the
following code:

return container.REQUEST

View this script and then view it as:

my_test?var1=foo&var2=bar

and see what that gives you.  Notice that you now have two variables
defined, var1 and var2.  Play around with this a bit, try posting a form
to it, etc.



> In looking thru the Shopping Cart Example I found a 
> form specifying in part
> 
> <form action="addItems">
> <input type="text" name="orders.quantity:records" ...
> 
> where addItems is a script in the same container, and addItems specifies 
> orders, REQUEST=None as parameters. What's missing for me is the 
> relationship between the form and the parameter list.


The form given to the client specifies an action of addItem.  That means
that when the client posts the form, the addItem object will be called. 
Because there is a field in the form called orders, the addItem
method/script will be passed the value that the client entered into the
orders field.  It's that simple... Zope makes form values *very* easy to
grab and manipulate.


> 
> In another example I experimented with a Page Template calculateForm:
> ...
>    <form action="calculateSum">
>      <input type="text" name="a" tal:attributes="value request/a"><br>
>      <input type="text" name="b" tal:attributes="value request/b"><br>
>      <input type="text" tal:attributes="value result"><br>
>      <input type=submit value="Submit" name="Next10">
>    </form>
> ...
> where calculateSum is script:
> 
> ## parameters a,b
> sum=int(a)+int(b)
> return container.calculateForm(result=sum)
> 
> After clicking Submit the form reappears, with the values for a and b 
> filled in. What is the magic that associates the values I entered for a and 
> b with the request to display the form again?

No magic... what is created by the Page Template is a *form* that the
*client* posts to the calculateSum script.  The *client* passes in these
parameters by posting a form that contain fields with names that match
the script's arguments.

Sometimes you want Zope objects manipulating one another directly...
more often, you create *interfaces* that allow the client to make
correctly-formed requests to the objects that do your heavy lifting. 
Don't forget that almost everything you do with Zope is initiated by a
client request and ends with information being transmitted back to
them.  If it seems like there's a step missing, it's usually because
that step is assumed to have taken place on the client side.

HTH,

Dylan




More information about the Zope mailing list