[Zope] image objects into table via python script
bruno
bruno at modulix.org
Thu Nov 18 04:36:01 EST 2004
John Schinnerer a écrit :
> Hello,
>
> --- J Cameron Cooper <jccooper at jcameroncooper.com> wrote:
>
>
>>First, and I think you know this, recall that you're not including
>>the Image object, but rather an HTML 'img' tag that will display the
>>image.
>
>
> Yes - in a ZPT referencing the image object automagically generates
> that tag. I was hoping I could get the same result in a python script
> without any 'gotchas'. Apparently not...
>
>
>>There could be any number of problems, but make sure that what you
>>think has an Image object in context actually does. Are you sure that
>>you're not being given a BLOB or a name?
>
>
> The objects I'm iterating over are instances of an ObjectManager-based
> class in a product I am building. Each instance contains one Image
> object, and that is what I am referencing.
> So afaik I am referencing an image object, yes.
>
>
>>To get the tag rendered from an Image, you can call the image. So put
>>a pair of parentheses on the end of the name. This should be the
>
> exact
>
>>same effect as the 'tag' method. (I do this by memory, so don't take
>>it as gospel.)
>
>
> Thanks, I hadn't thought of that - tried it, but still get the error.
> It is reported as a TALES attribute error but I think that is just what
> bubbles up from whatever error is generated in the python script when
> it tries to do:
>
> print(item.art_image())
>
>
>>Finally, you should re-think doing HTML in a script. That's really
>>what templates are for. You can use scripts for creating the list of
>>items or doing complex transformations, but actually creating the
>>HTML is not usually recommended.
>
>
> Yes, I know - unless as some say the TAL gets 'too' complicated or
> convoluted, in which case one 'should' move that logic to a python
> script - though perhaps not HTML generation.
> Anyhow...here is my situation:
>
> The number of items returned by a query will vary.
> So I need to generate a table with a fixed number of columns and a
> variable number of rows (last row not necessarily full). That is, a
> 2-D output, not just a 1-D list like in all the TAL 'repeat' examples
> I've ever seen or done so far.
> It was something I could figure out how to code in python.
> It was instant headache to try to code it in TAL.
>
> I am doing it with an explicit control variable in python - to know
> when to end one row and start another - and I don't know how that's
> possible in TAL. Is it?
>
> If someone can give an example in TAL of iterating over a variable
> number of items and generating a 2-D table with a fixed number of
> columns that would indeed be a more appropriate solution.
>
I gave you an exemple of nested repeats in a previous post. Now the only
thing you need is to add a level of indirection between the result of
the query and the TAL code. This is where you handle problems like
number of cells per row.
Instead of
+-------+ +---------+ +-----+
| query | ---> | results | ---> | ZPT |
+-------+ +---------+ +-----+
You want
+-------+ +---------+ +--------+ +-----+
| query | ---> | results | ---> | script | ---> | ZPT |
+-------+ +---------+ +--------+ +-----+
--
bruno
bruno at modulix.org
--
More information about the Zope
mailing list