[Zope] Re: How to return two images by one procedure

J Cameron Cooper jccooper@jcameroncooper.com
Wed, 02 Jul 2003 17:29:51 -0500


>
>
>>The better answer is to make two methods (one for image, one for key)
>>and give both methods the same parameters so they can create images on
>>the same information.
>>    
>>
>I considered this but it would be very bad because I would have to do
>the same database query twice which would cause quite bad performance.
>
>My second thought was that I do not really need two images because the
>second image could be replaced by one constant image containing plain
>colors and returning legend text description combining it with the
>image in a table - but this causes fiddling around with save placement
>in different browsers.  Moreover this reduces the problem only slightly:
>Replace return of two images by one image and a touple of text entries.
>
Then you should create one method to get the dynamic data and pass that 
as parameters to the methods that make your images.

>>That won't work if you have non-parameterized
>>controls (random or external), in which case you'll have to figure out
>>some sort of index/snapshot scheme.
>>    
>>
>I'm afraid I do not understand this sentence.
>  
>
I had a feeling that would be a little esoteric. What this might mean is 
that you something like the following:

1) Generate a random number with a high (or guaranteed, if you're 
feeling over-acheiving) probability of uniqueness.

2)Call your first method with a parameter being that number. It 
generates and returns your image, and caches the data the second method 
needs somehow under an index accessible by the number you gave it. (Like 
by filename.)

3) Call the second method with its parameter being the same index 
number. It retreives the cached data and creates its image. Perhaps it 
also flushes the cached value.

This works with any type of data created by the first method, even if 
it's random, by making a snapshot and providing the index to it. It's 
also somewhat fragile as described, because it depends on order of call, 
but I think you can imagine how to fix that. Probably you don't need to 
be this complex, and can use the simplified case I suggested above (the 
one using three methods.) Or you can use one of the previous suggestions 
that makes sense.

          --jcc