image objects into table via python script
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 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. thanks, John S. __________________________________ Do you Yahoo!? Meet the all-new My Yahoo! - Try it today! http://my.yahoo.com
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
Hello, --- Tino Wildenhain <tino@wildenhain.de> wrote:
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...
My complication is that I need a 2-D table with a fixed number of columns. I don't know how (if?) I can do that using TAL. If I iterate on <tr> I get just one column. If I iterate on <td> I get just one row. What I need is for example five columns per row, with rows added until the iteration is done. Anyone have an example of this in TAL? thanks, John S. __________________________________ Do you Yahoo!? The all-new My Yahoo! - Get yours free! http://my.yahoo.com
John Schinnerer a écrit :
Hello,
--- Tino Wildenhain <tino@wildenhain.de> wrote:
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...
My complication is that I need a 2-D table with a fixed number of columns. I don't know how (if?) I can do that using TAL.
If I iterate on <tr> I get just one column. If I iterate on <td> I get just one row.
What I need is for example five columns per row, with rows added until the iteration is done.
<tr tal:repeat="row here/get_rows"> <td tal:repeat="cell row/get_cells" tal:content="structure cell/get_content"> dummy </td> </tr> Now you just have to s/ get_rows, get_cells etc with whatever fits your needs. The 'five columns per row' problem is a responsability of row.get_cells(). HTH Bruno -- bruno bruno@modulix.org --
participants (3)
-
bruno -
John Schinnerer -
Tino Wildenhain