[ZPT] python to zpt
Charlie Clark
charlie at begeistert.org
Mon Jul 21 10:50:42 EDT 2003
On 2003-07-21 at 09:06:39 [+0200], Exteam wrote:
> hi all,
> i'm stuck at this point,
> can some one convert the following python code in to zpt & help me.
> i'm not able to convert it in to zpt.
> --------------------------------
> rec = context.test_select_sql()
> print "Fields definitions"
> recordset = rec.dictionaries()
> rownum = 1
> for record in recordset:
> print "Row %d" % (rownum), "check", record
> rownum = rownum + 1
> for key in record.keys():
> print key, "=", record[key]
> print "-" * 80
> return printed
> ---------------------------
Hello ???,
it would be nice if you included your real name in your e-mails. Have you
looked at the ZPT documentation? It should be quite straightforward to do
what you want but you might want to think more carefully about what that is
and how you want it to work. The current script would seem to produce a not
particularly helpful result and as it doesn't contain any HTML is not
really appropriate for ZPT.
A few pointers:
you can use Python within ZPT to get at Zope Objects
<body tal:define="results python: here.test_select();
dicts python:results.dictionaries();
keys python:results.names()">
<div tal:repeat="record dicts">
<br tal:content="record">
<span tal:repeat="key keys" tal:content="python: record[key]">
</span>
</div>
</body>
This is untested and probably flawed - it's just supposed to help.
ZPT is really about predictable layouts so having completely dynamic result
sets is not really the best way to use it. It is however, possible as far
as I know.
Charlie
More information about the ZPT
mailing list