[Zope] External method and image

Alexis Roda arv at si.urv.es
Fri Oct 17 05:03:35 EDT 2003


Michel Pottier wrote:
> Le jeu 16/10/2003 à 12:57, Alexis Roda a écrit :
> 
>>Do you mean that with something like
>>
>><dtml-var std_header>
> 
> here i have some initialisation of parameters
> 
>><dtml-var creGrapth>
>><dtml-var std_footer>
>>
>>you only get the image?
> 
> yes! In fact it replaces the whole html page with the jpeg image (when i
> view the html source i have only the jpeg file)
> 
>>I'm a bit lost. You have a form, the user submits some data to creGraph 
>>which paints something (depending on the submited data) that is returned 
>>to the user within an HTML page. Right?
> 
> submits some data to a dtml method where, among other action i call
> creGraph (which is an external method, but with script this is the
> same). And i get only the result of creGraph (the image)

I think the problem is in creGraph, with the

REQUET.RESPONSE.setHeader('Content-Type', 'image/jpeg')

If you call creGraph from the dtml method you're modifying the 
content-type for the whole HTML page. This will only work if you do 
something like:

<dtml-var header>
<img src="creGraph?param=value">
<dtml-var footer>

since the image will be retrieved by itself on a separate HTTP request.

> Thank you for the explanation, i will try that.

try this instead, is the same in python:

python script: creGraphParams
parameters: REQUEST

param_names=['foo', 'bar']
cgurl = ''
count = 0
for p in param_names :
   if count > 0 :
     cgurl = cgurl + '&'
   cgurl = cgurl + p + '=' + REQUEST.form[p]
   count = count + 1

# if there are no errors should return
# something like foo=1&bar=25

return cgurl
# end of script

in the dtml

<img src="creGraph?<dtml-var creGraphParams>">

> Yesterday evening, in
> place of returning my image from the external method, i return only the
> name of an "external file". So i have
> 
>>img src=link_to_python_script_which_return_name_of_external_file>
> 
> 
> in python_script_which_return_name_of_external_file
> * I run the external method
> * I get the name of the file
> * I add this file as external file
> * And now, i have only to solve the problem of removing this file (i
> think a cron will be used)

try Xron, a zope product.

> in external method, i create my image, i put it in a specific directory,
> i return the name of the file

img src=creGraph?parameters is simpler (you don't have to bother about 
deleting temporary files, lifetime etc.) but slower, since the image 
will be generated for every request.



HTH
-- 
                                   ////
                                  (@ @)
---------------------------oOO----(_)----OOo------------------------
         Los pecados de los tres mundos desapareceran conmigo.
Alexis Roda - Universitat Rovira i Virgili - Reus, Tarragona (Spain)
--------------------------------------------------------------------





More information about the Zope mailing list