[Zope-DB] Hello!

Jim Penny jpenny@universal-fasteners.com
Fri, 25 Jul 2003 11:33:20 -0400


On Fri, 25 Jul 2003 15:56:31 +0100
Philip Kilner <phil@xfr.co.uk> wrote:

> Hi Jim (& List!)
> 
> Jim Penny wrote:
> > 0)  I like the "Red Queen", "running in place" model.  (Damn I need
> > to write a howto on this.)
> > 
> > 1)  index_html is ALWAYS a Script (Python) in any of my code from
> > the last 18 months.
> > 
> 
> OK, so since this is our default "document", Zope will throw it when
> we hit our folder and so it controls the logic?

Right.

> 
> > 2)  The main form will have ZPT in it, only to do error handling.
> > 
> > The ISBN_entry_form_pt  [the tal presents an error message, if
> > present, and fills in the form with the most recent values if said
> > values are in the request.  This should happen only after an
> > error.]:
> > 
> > <html>
> >  <head><title>Enter ISBN Data</title>
> >  </head>
> >  <body>
> >  <h2>Enter ISBN Data</h2>
> > 
> >  <p color:red tal:content="options/error|nothing"></p>
> > 
> >  <form name="insert_book" action="." method="POST">
> >    <input type="text" name="field_ISBN"
> >       tal:content="request/field_ISBN|nothing">   <br>
> >    <input type="text" name="field_Title"
> >       tal:content="request/field_Title|nothing">   <br>
> >    <input type="text" name="field_Author"
> >       tal:content="request/field_Author|nothing">    <br>
> >   <input type="text" name="field_BookPrice"
> >       tal:content="request/Field_BookPrice|nothing">
> >   <input type="submit" name="next_state" value="Save ISBN Data">
> >  </form>
> >  </body>
> > </html>
> > 
> 
> OK, understand that - not sure why the form has: -
> 
> 	action="."
> 
> How does that work here - is it calling itself?

Well, kind of.  Think of it as an event loop.  The client receives a
form.  He submits it.  Now, what processes the submission?  In this
scheme, _the same index_html as was used to generate the form
in the first instance is responsible for processing the data_.  That is
the "running in place" part of the scheme.  We never leave the folder,
so we never have to redirect.

> 
> Other than that, this is the bit I think I understand! <wry grin>
> 
> > index_html looks like this (note:  per above, it is a Script
> > (Python)):
> > 
> > if not request.has_key('next_state'):
> >   return main_menu_form_pt(context, request)
> >   # main menu allows used to choose among usual CRUD operations
> >   # (CReate, Update, Delete), and probably offers reports
> > next_state=request['next_state']
> > if next_state=='Create ISBN Entry":
> >   return main_menu_form_pt(context, request)
> > elif next_state=='Save ISBN Data':
> >   error=container.check_save_ps()
> >   if error:
> >     return ISBN_Entry_form_pt(context, request, error=error)
> >   else:
> >     container.insert_ISBN_sql(field_ISBN=request['field_ISBN'],
> >       field_title=request['field_Title'],
> >       field_author=request['field_Author'],
> >       field_BookPrice=request['field_BookPrice'])
> >     return main_menu_form_pt(context, request)
> >       # You may want to return something else, if you are entering
> >       # in batches, it is better to return ISBN_entry_form_pt, for
> >       # example, but then you need breadcrumbs at the top of the
> >       form# so the user can get out of the loop.
> > 
> 
> OK, well I passed the test you had set me by converting the double
> quote to a single quote in 'Create ISBN Entry" <g>, but when I "test"
> this I get: -
> 
> 	Name Error: global name 'request' is not defined

OK, my fault (I like to define context and request as parameters to all
Script (Python)s except index_html (where you may not do so, due to the
ZPublisher machinery!), as it makes the calling sequence more uniform. 
make the first line of your script: 

request=context.REQUEST

> 
> 	(N.B. This is in Plone - will try in raw Zope next)
> 
> Is insert_ISBN_sql our ZSQL method here?

Right, the ZSQL method that does an insert.  You will probably also have
an update, and a delete method, and certainly one or more select
methods.

> 
> > main_menu_form_pt may be as simple as:
> > 
> > <html>
> > <body>
> >   <head>
> >     <title>Choose Action</title>
> >   </head>
> >   <form method="." action="post">
> >     <input type="submit" name="next_state" value="Create ISBN
> >     Entry"><input type="submit" name="next_state" value="Edit ISBN
> >     Entry"><input type="submit" name="next_state" value="Delete ISBN
> >     Entry">
> >   </form>
> > </html>
> > 
> 
> Same question about "method" here as for "action" above - how the
> period works? Are these transposed by any chance?

Yeah, transposed.  Hey, this was composed at screen without testing....
;-P

Jim

> 
> As you can see, I'm floundering a bit - if you could help me take this
> 
> (apparently simple - but crytpic to me - script apart a little
> further, I'd be very grateful.
> 
> I understand - I think - the differnce in principle in what we are
> doing here, but am lost in the syntax. I can see that once I have a
> working example I have a theme to create variations on!!!
> 
> -- 
> 
> Regards,
> 
> PhilK
> 
> Email: phil@xfr.co.uk / Voicemail & Facsimile: 07092 070518
> 
> "the symbols of the divine show up in our world initially at the trash
> 
> stratum." Philip K Dick
> 
>