[Zope] image objects into table via python script

Tino Wildenhain tino at wildenhain.de
Wed Nov 17 17:11:52 EST 2004


Am Mittwoch, den 17.11.2004, 13:14 -0800 schrieb John Schinnerer:
> Hello,
> 
> I am using a python script to generate an HTML table structure.
> The script is called from a page template, like this:
> <span tal:replace="structure
> python:container.renderTable('CatalogQueryParameter')" />
> The script (renderTable) iterates over items returned from a catalog
> query which is passed one parameter.
> To put for example a date or string property in the table is easy, like
> this:
> 
> ...
> for item in resultItems:
> 	print("<td>")
> 	print(item.creation_date.strftime('%B %Y'))
> 	print("</td>")
>         ...
> return printed


Well, what would be wrong if you use:

<table>
 <tr>
   <td tal:repeat="item here/thescript"
tal:content="item/formattettime />
 </tr>
</table>

or even repeat over tr is you need...





> What I really need to put in the table, though, are Image objects that
> are part of the objects returned.
> 
> How can I put the Image object into the table structure returned by the
> script, so that the Image object will render itself as usual?  That is,
> as it would in for example:
> 
> <span tal:replace="structure here/art_image" />
> 
> The below of course does not work (art_image is an Image object in the
> item object) - it gives a TALES attribute error on art_image:
> 
> ...
> for item in BGitems:
> 	print("<td>")
> 	print(item.art_image)
> 	print("</td>")
>         ...
> return printed
> 
> ...and I am stuck on how to get the art_image Image object into the
> table returned by the script.

Zopes image objects return a HTML image tag if you call str(imageobject)
or use it in print (which calls str() in turn)
You can use it like above (the ugly way) 
or return it as structure in ZPT or
even

<img src="dummy" tal:attributes="src img/src; width img/width; height
img/height; alt img/alt" />

a little more writing but more ZPT-ish

Regards
Tino



More information about the Zope mailing list