[Zope] return structured result from Python scripts for page templates

Nagypal Gabor nagypalg@freemail.hu
Thu, 25 Jul 2002 15:35:54 +0200


Oops, it was my mistake. The dictionary solution works! I do not know, 
why has it failed for the first time.
I think the stuff is interesting enough to explain short the solution here.
So the solution is:

Python script get_persons:

result = []

result.append({'name':'Jack','title':'Mr.'})
result.append({'name':'Joe','title':'Mr.'})
result.append({'name':'Mary','title':'Ms.'})

return result

A possible page template:
<html>
   <head>
     <title tal:content="template/title">The title</title>
   </head>
<body>
<table>
<tr tal:repeat="item container/get_persons">
<td tal:content="item/name">Kate</td>
<td tal:content="item/title">Mrs.</td>
</tr>
</table>
</body>
</html>


Nagypal Gabor wrote:
> I tried to create external script, but this does not help. The result is 
> practically the same.
> Anyway, I do not insist on creating objects. I just would like to have a 
> way to return a structured result from a Python script, where I can 
> access the named attributes easily. I have seen an example in a how-to, 
> how to do it with dictionaries and DTML (specifying a "mapping" 
> parameter for dtml-in), but it does not work for page templates (or at 
> least the simple item/attribute notation does not work, and the mapping 
> parameter does not exist in TALES path expressions).
> 
> Gabor
> 
> Max M wrote:
> 
>> Gabor Nagypal wrote:
>>
>>> I would like to return a structured result (an "object") from a 
>>> Python script to use it conveniently in a page template. E.g. I would 
>>> like to have a get_person Python script which gives back a person 
>>> with a name and an address. Then I could use a page template like: 
>>
>>
>>
>>
>> I don't think you can create objects in a Python script. You need to 
>> create an external script for that.
>>
>> Otherwise your code looks dandy.
>>
>> regards Max M
>>
> 
> 
> 
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce
> http://lists.zope.org/mailman/listinfo/zope-dev )
> 
> 
> 
>