[Zope] zope tal / external method woes continued...

J Cameron Cooper jccooper@jcameroncooper.com
Mon, 30 Jun 2003 15:15:10 -0500

>I (finally) got my permissions problem with my external method solved, by
>changing the ext method to return a list of lists:
>def getAll:
>   rows = ... # get data from soap call
>   results []
>   for row in rows
>      results.append( row[0], row[1], row[2] )
>   return results
>this gets the data and returns it in a list of lists:
>[['1', 'Fido', '5.00'], ['2', 'Spot', '10.00'], ['4', 'Sparky', '24'], ['9',
>'Buffy', '10'], ['10', 'Bobby', '50']]
>my tal code looks like the following:
>  <p tal:content="here/getRecords"> </p>
>    <table border="1" tal:define="data python:here.getRecords()">
>    <tr tal:repeat="record data">  
>        <td tal:content="python:record[0]">record item 1</td>
>        <td tal:content="python:record[1]">record item 2</td>
>        <td tal:content="python:record[2]">record item 3</td>
>    </tr>
>    </table>
>Neither of the above work... on both counts, now I get:
>Exception traceback
>Time 2003/06/30 15:32:49.218 US/Eastern
>User Name (User Id) Anonymous User (None)
>Request URL http://jhoodxp.hmcon.com:8081/jhood/show_records
>Exception Type TypeError
>Exception Value sequence index must be integer
>Traceback (innermost last):
>TypeError: sequence index must be integer
>It seems (to me with my limited python/zope knowledge) that the tal is
>looking for something other than a list of lists, and it can't handle it... 
>although now at least I don't have security issues...  
>Question is...  what can I do ???  If I have to change the return value,
>what should it be, and if I can use it, how can I use it with tal...  
It works for me when I use the list representation you gave as the 
return value of a Python Script, suggesting that the problem is not in 
the display. It may be because of a typo in your external method, which 
should say::

results = []

Notice the 'gets'.

Make sure you're returning what you think you're returning. If that's 
not it, you need to take a good close look at that traceback. The 
problem is probably exposed in /jhood/show_records around line 34. Is 
that where the code you show above came from? Trace back where you got 

Fyi, I can also do::

    <table border="1" tal:define="data python:here.asdf()">
    <tr tal:repeat="record data"> 
        <td tal:repeat="elt record"><span tal:replace="elt"/></td>