zope tal / external method woes continued...
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): * Module ZPublisher.Publish, line 98, in publish * Module ZPublisher.mapply, line 88, in mapply * Module ZPublisher.Publish, line 39, in call_object * Module Shared.DC.Scripts.Bindings, line 252, in __call__ * Module Shared.DC.Scripts.Bindings, line 283, in _bindAndExec * Module Products.PageTemplates.ZopePageTemplate, line 228, in _exec * Module Products.PageTemplates.PageTemplate, line 95, in pt_render <ZopePageTemplate at /jhood/show_records> * Module TAL.TALInterpreter, line 200, in __call__ * Module TAL.TALInterpreter, line 244, in interpret * Module TAL.TALInterpreter, line 497, in do_insertText_tal * Module Products.PageTemplates.TALES, line 223, in evaluateText * Module Products.PageTemplates.TALES, line 217, in evaluate URL: /jhood/show_records Line 34, Column 8 Expression: standard:'records/item' Names: {'container': <Folder instance at 01EAAC68>, 'default': <Products.PageTemplates.TALES.Default instance at 008AFF6C>, 'here': <Folder instance at 01EAAC68>, 'loop': <SafeMapping instance at 01F62578>, 'modules': <Products.PageTemplates.ZRPythonExpr._SecureModuleImporter instance at 008B0024>, 'nothing': None, 'options': {'args': ()}, 'repeat': <SafeMapping instance at 01F62578>, 'request': <HTTPRequest, URL=http://jhoodxp.hmcon.com:8081/jhood/show_records>, 'root': <Application instance at 019B27C8>, 'template': <ZopePageTemplate at /jhood/show_records>, 'traverse_subpath': [], 'user': Anonymous User} * Module Products.PageTemplates.Expressions, line 206, in __call__ * Module Products.PageTemplates.Expressions, line 194, in _eval * Module Products.PageTemplates.Expressions, line 150, in _eval __traceback_info__: records * Module Products.PageTemplates.Expressions, line 353, in restrictedTraverse __traceback_info__: {'path': ['item'], 'TraversalRequestNameStack': []} 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... This is driving me mad, since I *really* would like to use Zope for a project, but this is almost getting too frustrating... Thanks in advance... JH jhood .a. hmcon .d. com
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 'item'. 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> </tr> </table> --jcc
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 'item'.
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> </tr> </table>
--jcc
Thanks a million... you pointed me to what happened to be the fault... I *assumed* (obviously incorrectly) that tal that was <!-- --> commented out wasn't running or being interpreted... that line was in code that I thought was commented out, and now all works as it should... thanks again for getting me in the right direction... JH -- jhood .a. hmcon -d- com
Jeffrey Hood wrote at 2003-6-30 15:38 -0400:
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
Strange that this works. I would expect a "TypeError: 'append' takes a single argument".
... 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> ... ------------------------------------------------------------------- Exception traceback ... URL: /jhood/show_records Line 34, Column 8 Expression: standard:'records/item' Names: ... restrictedTraverse __traceback_info__: {'path': ['item'], 'TraversalRequestNameStack': []}
TypeError: sequence index must be integer
Your code extract does not correspond to this traceback. In line 34 of "show_records" you use "records/item" (which does not occur in your code extract). There, "records" is a sequence but 'item' is a string. This results in the TypeError you observe. Unless you access the built in methods of a sequence (e.g. of a list), you must use "python:" expressions to access sequence components. Dieter
participants (3)
-
Dieter Maurer -
J Cameron Cooper -
Jeffrey Hood