Hi, It's probably a newbie question : I want to write a python script form action which return a file to download: In a folder i have 2 files ("A.tgz" and "B.tgz") and a Page Template Object (download.html). This page is a form with multiple choice in order to seclect a file to download (if the user select "A" button, he get the A.tgz file, if select "B" he get A.tgz ...) I want to write a python script method to render the file but i don't know how create the command to pass the file to downlown. I don't find any example, and i'm very glad if anybody can help me ! Thanks _____________________________________________________________________________ Herve RICHARD Herve.Richard@avignon.inra.fr INRA - Biometrie
Hervé Richard wrote at 2003-12-4 15:30 +0100:
It's probably a newbie question : I want to write a python script form action which return a file to download: In a folder i have 2 files ("A.tgz" and "B.tgz") and a Page Template Object (download.html). This page is a form with multiple choice in order to seclect a file to download (if the user select "A" button, he get the A.tgz file, if select "B" he get A.tgz ...) I want to write a python script method to render the file but i don't know how create the command to pass the file to downlown.
I do not understand what you mean with "create the command to pass the file". If the file is a Zope "File" object, then its "index_html" renders its content. Your PythonScript could return in this case: return fileObject.index_html(container.REQUEST, container.REQUEST.RESPONSE ) -- Dieter
Tanks for your answer, It almost works but ... here is my script (named "sendMeAr") : ---------------- # 3 differents formats compressed files : archiveMac ='arMacV2.sea.hqx' #these files are in my current folder archiveWin ='arWinV2.zip' archiveUnix='arUnixV2.tar.gz' fileObj='' #I get the response from the form : OS = request.form systeme = OS['submit'] if systeme == 'Unix': container.Ar_Unix.increment(1) fileObj = getattr(context, archiveUnix) elif systeme == ' Mac': container.Ar_Mac.increment(1) fileObj = getattr(context, archiveMac) elif systeme == ' Win': container.Ar_Win.increment(1) fileObj = getattr(context, archiveWin) return fileObj.index_html(context.REQUEST, context.REQUEST.RESPONSE) ------------------------- When i try, if i hit Unix button i get the popup to download arUnixV2.tar.gz, and so on, BUT the name of each of file is : for mac button : sendMeAr29ac392e in place of arMacV2.sea.hqx for unix button : sendMeAr39d43f39 in place of arWinV2.zip for win button : sendMeAr3a318f43 in place of arUnixV2.tar.gz How can i pass the good attr name to the return file ? Tanks again Dieter Maurer wrote:
Hervé Richard wrote at 2003-12-4 15:30 +0100:
It's probably a newbie question : I want to write a python script form action which return a file to download: In a folder i have 2 files ("A.tgz" and "B.tgz") and a Page Template Object (download.html). This page is a form with multiple choice in order to seclect a file to download (if the user select "A" button, he get the A.tgz file, if select "B" he get A.tgz ...) I want to write a python script method to render the file but i don't know how create the command to pass the file to downlown.
I do not understand what you mean with "create the command to pass the file".
If the file is a Zope "File" object, then its "index_html" renders its content. Your PythonScript could return in this case:
return fileObject.index_html(container.REQUEST, container.REQUEST.RESPONSE )
-- _____________________________________________________________________________ Herve RICHARD Herve.Richard@avignon.inra.fr INRA - Biometrie _____________________________________________________________________________
Hervé Richard wrote at 2003-12-5 15:53 +0100:
It almost works but ... here is my script (named "sendMeAr") : ... return fileObj.index_html(context.REQUEST, context.REQUEST.RESPONSE) ------------------------- When i try, if i hit Unix button i get the popup to download arUnixV2.tar.gz, and so on, BUT the name of each of file is : for mac button : sendMeAr29ac392e in place of arMacV2.sea.hqx for unix button : sendMeAr39d43f39 in place of arWinV2.zip for win button : sendMeAr3a318f43 in place of arUnixV2.tar.gz
You seem to have a funny browser :-) The "Content-Disposition" header should allow you to control the filename. Search for details. Some browsers, especially some version of IE, think they know better and ignore the header. In this case, it is necessary to provide the wanted filename as last URL component. This is possible with a PythonScript and it "traversal_subpath". Read about this feature in the Zope Book (2.6 edition, online). -- Dieter
participants (2)
-
Dieter Maurer -
Hervé Richard