[Zope-DB] Re: Form evaluation in ZSQL-Method
Andreas Tille
tillea at rki.de
Mon Sep 22 08:56:33 EDT 2003
Hi once more.
This is the result from my debugging. It should be easy to reproduce
I just created a simple database using the following script:
#!/bin/sh
DBNAME=testzopeform
createdb $DBNAME
psql $DBNAME <<...
CREATE TABLE test (
iditem int NOT NULL,
item varchar(32) NOT NULL
) ;
GRANT ALL ON test TO zope;
...
i=0
while [ $i -lt 30 ] ; do
item="item $i"
echo "INSERT INTO test VALUES ($i, '$item');" | psql $DBNAME
i=$(($i+1))
done
(or just use an existing database). Then I created a Database Connection
Object and connected it to this database. Next I created the following
ZSQL object:
<params>iditem</params>
select * from test
<dtml-sqlgroup where>
<dtml-if "_.int(iditem)>0">
<dtml-sqltest iditem column=iditem op=eq type=nb optional>
</dtml-if>
</dtml-sqlgroup>
Using "Z Search Interface" I've got the both page templates I appended to the
end of this mail (they are completely unchanged).
If I call the search.html form with an integer not equal to 0 all is as expected.
If I use 0 as iditem I get the first 20 items and if I follow "next 10 results"
I get exactly the same error I reported from my more complex application:
Zope Error
Zope has encountered an error while publishing this resource.
Error Type: NameError
Error Value: global name 'iditem' is not defined
Anybody able to reproduce or rather to fix this problem?
Kind regards
Andreas.
search.html:
<html><body>
<form action="report.html" method="get">
<h2 tal:content="template/title_or_id">Title</h2>
Enter query parameters:<br><table>
<tr><th>Iditem</th>
<td><input name="iditem"
width=30 value=""></td></tr>
<tr><td colspan=2 align=center>
<input type="SUBMIT" name="SUBMIT" value="Submit Query">
</td></tr>
</table>
</form>
</body></html>
report.html:
<html><body>
<html>
<body tal:define="results here/test;
start request/start|python:0;
batch python:modules['ZTUtils'].Batch(results,
size=20,
start=start);
previous python:batch.previous;
next python:batch.next">
<p>
<a tal:condition="previous"
tal:attributes="href string:${request/URL0}?start:int=${previous/first}"
href="previous_url">previous <span tal:replace="previous/length">20</span> results</a>
<a tal:condition="next"
tal:attributes="href string:${request/URL0}?start:int=${next/first}"
href="next_url">next <span tal:replace="next/length">20</span> results</a>
</p>
<table border>
<tr>
<th>Iditem</th>
<th>Item</th>
</tr>
<div tal:repeat="result batch" >
<tr>
<td><span tal:replace="result/iditem">iditem goes here</span></td>
<td><span tal:replace="result/item">item goes here</span></td>
</tr>
</div>
</table>
<p>
<a tal:condition="previous"
tal:attributes="href string:${request/URL0}?start:int=${previous/first}"
href="previous_url">previous <span tal:replace="previous/length">20</span> results</a>
<a tal:condition="next"
tal:attributes="href string:${request/URL0}?start:int=${next/first}"
href="next_url">next <span tal:replace="next/length">20</span> results</a>
</p>
</body>
</html>
</body></html>
More information about the Zope-DB
mailing list