[Zope] Zope 2.4 / DTML problem: With looping over two sets
spex66@yahoo.com
spex66@yahoo.com
Tue, 21 Aug 2001 00:14:41 -0000
Hi there,
maybe a newbie question...
I try to dtml a cursor-object of an own python-database, swigged from
a C-project (Gigabase).
Actual the cursor-class has __getitem__ with throwing of IndexError.
BUT: it has no real random access via index-number!
its behavior is like this (a little bit simplifying):
...
cursor.first() #get first position
cursor[anyNumber] #if number == 0: return cursor.get()
#else: cursor.next().get()
#if next() has no result or number > len
(cursor), or len(cursor)==0 the exception is thrown and a loop will
stop
...
so, a simple code-snippet
cursor.first()
for c in cursor:
for r in c.rows:
...process something...
works perfect for me!
Now following DTML-code makes a unaccepted error (I've had very few
accepted errors :-))... obviously the render-code access the
cursor.__getitem__ method in second loop (-->c_item) again with
static index-number!
Bad for my stupid implementation, and not pythonlike where a loop in
a loop works with an own loop-variable.
I doesn't expect a continous __getitem__ with 'same' index-number,
and I don't know how to workaround it on C-language-site
first steps to program this page (and this is only the beginning!)
the "classic" way, leads me directly to your mailinggroup and the
urgent wink for help!!! I like the DTML way, and I want to use it!
Anybody a tip or patch, workaround, whatever???
thanks a lot
Peter
(=PA=)
:
t = DocumentTemplate.HTML("""
<html><head><title><dtml-var
expr="cursor.entityName"></title></head>
<body>
<dtml-if expr="cursor.__len__()">
<p>Die Suche ergab <dtml-var expr="cursor.__len__()"> Treffer!
</p>
<table>
<tr>
<dtml-in expr="cursor.rowNames"> <----- OUTER LOOP
<th><dtml-var sequence-item></th>
</dtml-in>
<tr>
<dtml-in cursor prefix="c"> <------ INNER LOOP
<tr>
<dtml-in expr="cursor.rowNames" prefix="r">
<td><dtml-var expr="c_item.__getattr__
(r_item)"></td> <---- c_item access my cursor again with __getitem__!
instead of a loop-variable
</dtml-in>
</tr>
</dtml-in>
</table>
<dtml-else>
<p>Die Suche ergab keine Treffer!</p>
</dtml-if>
<p>Generated by Miracle</p>
</body>
</html>
""")