[ZPT] Two column ZPT output from SQL

Duane Raymond duane.raymond at gmail.com
Tue Oct 5 14:00:17 EDT 2004


OK - I've got this working now - thanks for your help!  The working
code is pasted below.

> > Sorry for being a bit slow - <snip> 
> Well, I have to say this is somewhat basic understanding
> of the language (the attributename, function call is
> similar across most languages)

Last time I took a programming class was 1982 on a Commadore Pet - so
things have changed a little since then :-)  I understand the concept
clearly - it's the syntax and function names that always throw me.

========= Python Script:getSQLList  ==========
columns=2 # the number of columns needed - can be a python script parameter
query="sql_myQuery" # the name of the ZSQL Method - can be a python
script parameter

# this is the line I had trouble with
qresults = getattr(context, query)(var1=var1,var2=var2).dictionaries()
# this is done to get a real list from the query results

return [qresults[index:index+columns] for index in
range(0,len(qresults),columns)]
==============================

========= Page Template Code ==========
<table width="100%" border=0 cellpadding=2>
<tr tal:repeat="row
python:here.getSQLList(var1=var1,var2=var2,columns=3,query='sql_myQuery')">
  <td tal:repeat="col row" valign=top>
     <a href="" tal:attributes="href col/columnname"
                tal:content="col/columnname">samplvalue</a>
  </td>
</tr>
</table>
===================================


More information about the ZPT mailing list