Can anyone provide some insight regarding the problem detailed below? Basically, I would like to add file attachment support to the ZDiscussion product. I have managed to do that successfully, however I cannot seem to create a URL to access the file such that it could be wrapped inside an HREF tag. Any help would be greatly appreciated. -Brian
-----Original Message----- From: Pearson, Brian Edward (GEA, 056278) Sent: Thursday, March 16, 2000 5:20 PM To: 'zope-dev@zope.org' Subject: ZDiscussions
All,
Have been trying to add File Attachment functionality to the ZDiscussions Product. Thus far, I have modded the ZDiscussions.py file, specifically the ZDItem class's __init__ method, to accept one extra parameter called file. The corresponding DTML-Method (postForm) within the ZDiscussion object has been modded to include a FILE input field.
To facilitate the file handling, I am using the Squishfile.py module. All is working well, and via a new def attachment(self) method that was added to the ZDiscussion.py module, I am able to return the file to the browser.
Herein lies the problem. How can I reference the file via an HREF? With the following DTML:
<dtml-if attachment> <b>Hello there</B> <tr><th bgcolor="#d0d0f0" align=left>Attachment:</th><td> <dtml-in attachment> <A HREF="./<dtml-var file_name url_quote>"> <IMG SRC="<dtml-var SCRIPT_NAME >/<dtml-var icon >" HEIGHT=16 WIDTH=16 BORDER="0" ALT="Click to download attachment"></A> <A HREF="./<dtml-var file_name url_quote>"> <dtml-var file_name></A> <dtml-var file_kbytes>KB (<dtml-var file_bytes> bytes)<BR> </dtml-in attachment></td> </dtml-if>
This of course references the file object as absolute_url/ZDItem_id/file_name. This same reference url is used in the Squishdot product when displaying a link the user may click on to download the file. However, in my implementation it is not referencing the file.
The only way to reference the file is to use <dtml-var attachment>, which means that the file will be streamed to the user as soon as they click on the message thread, obviously not the way I would like to handle the situation.
Do I need to include the file object as a property of the message? I thought by including the file object during the creation (__init__) method of ZDItem this would be handled.
Any/all assistance would be greatly appreciated. Also, if I am crazy for doing this please let me know. Perhaps a new ZDiscussion already exists that supports attachments?
Thanks again, -Brian
"Pearson, Brian Edward (GEA, 056278)" wrote:
Can anyone provide some insight regarding the problem detailed below? Basically, I would like to add file attachment support to the ZDiscussion product. I have managed to do that successfully, however I cannot seem to create a URL to access the file such that it could be wrapped inside an HREF tag.
Any help would be greatly appreciated.
You'll probably need to create a function that sets the headers and mime types correctly, and returns the file data, then have the href point to that function. I've done this to return to the client a file that had been written to the filesystem. With a bit of modification, this should do what you need: # UNTESTED CODE based on working code... should work. def downloadAttachment(self, RESPONSE): RESPONSE.setHeader('content-type', 'application/octet-stream') RESPONSE.setHeader('Content-Disposition', 'attachment; filename=%s' % self.attachment_name); RESPONSE.write(self.attachment_data) What this should do is, when the user clicks the href that points to this function it will pop up a Save File dialog box with self.attachment_name as the filename (otherwise it will use the function name, which we don't really want). One caveat of doing it this way, is that it won't pop up the download window until _after_ the whole file is downloaded. Presumably, Netscape then simply renames the file in the cache to the desired filename. Anyway, this should point you in the right direction. -- Nick Garcia | ngarcia@codeit.com CodeIt Computing | http://codeit.com
On Mon, Mar 20, 2000 at 05:26:45PM -0500, Pearson, Brian Edward (GEA, 056278) wrote:
Can anyone provide some insight regarding the problem detailed below? Basically, I would like to add file attachment support to the ZDiscussion product. I have managed to do that successfully, however I cannot seem to create a URL to access the file such that it could be wrapped inside an HREF tag.
Any/all assistance would be greatly appreciated. Also, if I am crazy for doing this please let me know. Perhaps a new ZDiscussion already exists that supports attachments?
IMVHO you're throwing away the simplicity and flexibility (and Zope-Zen) that make ZDiscussions great. Q. How do you add a file to a Zope object? A. Make the object folder-like and drop a File object in there. This way you can make it an Image instead if you wish, or any other Zope object your heart feels like enabling (if you subclass ObjectManager instead of Folder, you can choose which classes of sub-objects are acceptable) and support more than one attachment easily. The ZD Topic object is already folderlike. The only thing you need is a folderlike ZDItem (by creating a ZClass combining ZDItem and ObjectManager), and then write forms and constructors that do the hard work of attaching. []s, |alo +---- -- Hack and Roll ( http://www.hackandroll.org ) News for, uh, whatever it is that we are. http://www.webcom.com/lalo mailto:lalo@hackandroll.org pgp key in the personal page Debian GNU/Linux --- http://www.debian.org Brazil of Darkness --- http://zope.gf.com.br/BroDar
participants (3)
-
Lalo Martins -
Nick Garcia -
Pearson, Brian Edward (GEA, 056278)