[Zope] ZPT, DTML, SQL and Forms

Jeff Peterson jpeterso@rangebroadband.com
Tue, 26 Mar 2002 17:48:26 -0600


Off the top of my head you could pass a parameter to the script which
describes the action you wish to proceed with and then do an if/then kind of
thing on the possible sql queries, this is hackish but would work.

I would have to do some looking to figure out a slicker way and
unfortunately I am out of time for today.  If I come up with a better way
I'll let you know.

Glad I could help some anyway,

--
Jeffrey D. Peterson
Webmaster & Resident Standards Warrior
"The Trouble with doing anything right the first time is that nobody
appreciates how difficult it was."

> -----Original Message-----
> From: Colin Fox [mailto:cfox@crystalcherry.com]
> Sent: Tuesday, March 26, 2002 5:30 PM
> To: jpeterso@rangebroadband.com
> Cc: zope@zope.org
> Subject: RE: [Zope] ZPT, DTML, SQL and Forms
>
>
> On Tue, 2002-03-26 at 08:29, Jeff Peterson wrote:
> <...>
> > Well, you need to execute the ZSQL method obviously, and you can do this
> > more than one way:
> >
> > One way to do it is to call it in a Script (python) and pass
> the information
> > by the request namespace:
> >
> > Script (python)
> > ===============
> >
> > data = context.your_sql([param=value])
> > #assuming you returned 1 row
> > context.REQUEST.set('field', data[0]['colname'])
> > return context.your_template(context)
> >
> > then
> >
> >   <tr>
> >     <td><LABEL for="firstname">First name: </LABEL></td>
> >     <td><INPUT type="text" name="first_name" value=""
> >                tal:attributes="value request/field"
> >                tal:on-error="string:">
> >     </td>
> >   </tr>
>
> Thanks Jeff - this got me going again. I've decided to go this route,
> because it keeps the template very simple. My script ended up being:
>
> res = context.get_customer(personid=pid)
> d = res.dictionaries()[0]
> for k in d.keys():
>     context.REQUEST.set(k, d[k])
>
> Since the column names are (intentionally) the same as the input field
> names, I can get away with just using they key values.
>
> Now that I think of it, this script is quite generic, except for the
> call to get_customer(). I'm going to have at least 2 more add/edit/seach
> sections within my site, and I'm going to end up copying all this stuff
> and just renaming one function call.
>
> It would be great if I could call this "populate" or something, and just
> pass the name of the sql query to execute. I'm not sure how to do this
> in Zope (in Python, I could just create a function object to execute,
> but I don't know if that's possible in zope, or if so, what the
> semantics are).
>
> I have an allergy to cutting/pasting code and only changing one thing.
> I'd really like to parameterize as much as possible.
>
> Any ideas?
>
> --
> Colin Fox                                       cfox@crystalcherry.com
> CF Consulting Inc.                                    GPG Fingerprint:
>                     D8F0 84E7 E7CC 5C6C 9982  F1A7 A3EB 6EA3 BC97 572F
>