[Zope] ZPT, DTML, SQL and Forms
Colin Fox
cfox@crystalcherry.com
26 Mar 2002 15:29:32 -0800
--=-I5MYGfkCxCDWFfI1+gUR
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable
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:
>=20
> One way to do it is to call it in a Script (python) and pass the informat=
ion
> by the request namespace:
>=20
> Script (python)
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>=20
> data =3D context.your_sql([param=3Dvalue])
> #assuming you returned 1 row
> context.REQUEST.set('field', data[0]['colname'])
> return context.your_template(context)
>=20
> then
>=20
> <tr>
> <td><LABEL for=3D"firstname">First name: </LABEL></td>
> <td><INPUT type=3D"text" name=3D"first_name" value=3D""
> tal:attributes=3D"value request/field"
> tal:on-error=3D"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 =3D context.get_customer(personid=3Dpid)
d =3D 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?
--=20
Colin Fox cfox@crystalcherry.com
CF Consulting Inc. GPG Fingerprint:
D8F0 84E7 E7CC 5C6C 9982 F1A7 A3EB 6EA3 BC97 572F
--=-I5MYGfkCxCDWFfI1+gUR
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQA8oQRco+tuo7yXVy8RAmhTAJ0bydcLtRBFNRG3PaoR1DaWlKSd6QCdFzAi
wsb3cGH5DckYgvoTOX/ClLE=
=1YL6
-----END PGP SIGNATURE-----
--=-I5MYGfkCxCDWFfI1+gUR--