[ZPT] Best way of getting the first results from ZSQL queries

Tony McDonald tony.mcdonald@ncl.ac.uk
Thu, 05 Sep 2002 06:28:26 +0100


Hi all,
I have a situation that requires I show a form ready for data to be entered
or populate that form with data that will be edited.

Whether the form is populated or not depends on whether a variable (autoid)
is passed to the template.

What I have is this. It
(1) checks whether autoid exists
(2) does the ZSQL query (it's only ever going to get zero or one row)
(3) checks to see that it got a row
(4) if it did, it sets a global variable

<tal:autoid_exists condition="exists:request/autoid">
<tal:formdef define="form_data_list
python:here.get_teaching(autoid=request['autoid'])">
 <tal:if condition="python:len(form_data_list)>0">
  <tal:call define="global form_data python:form_data_list[0]"/>
 </tal:if>
</tal:formdef>
</tal:autoid_exists>

My form elements have things like
tal:content="form_data/surname | nothing"
So if form_data does not exist, the whole thing doesn't break.

My question is simple - is this the best way to do this, it seems *really*
clunky, and I'm loathe to show it to my troops who are just getting into ZPT
as it would likely make them run away screaming.

Any thoughts would be appreciated.
Tone.
-- 
Dr Tony McDonald,  Assistant Director, FMCC, http://www.fmcc.org.uk/
The Medical School, Newcastle University Tel: +44 191 243 6140
A Zope list for UK HE/FE  http://www.fmcc.org.uk/mailman/listinfo/zope