README
ZAttachmentAttribute : an attachment helper class.
INSTALL
Use the usual Install script in Extensions IF AND ONLY IF you want to use the AttachmentDemo dummy content type within Plone OR use the given icon files.
HOW DOES IT WORK
ZAttachmentAttribute is used to help use of simple attachment files with user-created Zope products. It is pluggable, which means you can make it support new file types.
HOW CAN YOU USE IT
To use ZAttachmentAttribute within your product class, just follow the ZAADemo class example :
- Put somewhere in your instanciation code the following line:
self.myAttachment = ZAttachmentAttribute.ZAttachmentAttribute( AccessControl.Permissions.view_management_screens, AccessControl.Permissions.change_images_and_files )
Of course you have to change permissions in order to support your whished permission settings. The first permission given is the permission used to allow a user to view/download the file, the second given is used to allow a user to edit/upload a file.
- Create an uploadAttachment method in your product like this:
def uploadAttachment(self, file, REQUEST = {}): """ uploadAttachment(self, file, REQUEST = {}) -> upload an attachment file """ self.myAttachment.upload(file) if REQUEST.has_key('RESPONSE'): return REQUEST.RESPONSE.redirect(self.absolute_url() + '/manage_main')
Of course you can edit it to suit your needs. You can also delegate a Python Script to do the job. The main
method of an attachmentAttribute is upload
(which takes an HTTP file object) which uploads and possibly
indexes the file.
- Create or edit a principia_search_source that will return the value given by
self.myAttachment.listIndexableValues
. I don't know the principia_search_source method name suitable for Plone or the CMF. - Create or edit your editing HTML code to include the following things:
<!-- Upload form --> <form action="uploadAttachment" method="POST" enctype="multipart/form-data"> <input type="file" name="file" /><br /> <input type="submit"> </form> <!-- Download form --> <img src="myAttachment/getIcon" /><a href="myAttachment">Download myAttachment</a>.
Now you're done : you should be trying your new myAttachment property behaviour.
CLASS INTERFACE
A few methods can be useful for you.
- upload(file) -> Upload the given file and possibly index it
- getIcon() -> return the type's icon as a stream
- listIndexableValues() -> return a list of all distinct indexed words. This is useful to index a PDF file into the ZCatalog, for example.
- getIndexableValue() -> same as listIndexableValues but return a string of non-unique words
- getFile() -> return the file as a string. Only use this within your code, not through a URL (see index_html below)
- index_html -> return the file (but suitable as a URL, for example myObject/myAttachment will return the file). This method deals with returned content-type as well.
HOW TO TEST
You can check that everything works by doing the following things :
- touch a
debug.txt
file in your ZAttachmentAttribute product directory. This will enable special product initialization including test classes. - Restart Zope (this is a must-do even if you are using the auto-refresh feature)
- Instanciate somewhere in your ZODB a ZAADemo object and check the
Upload
tab works properly. Please take consideration of the bugs below before complaining ! :-)
HOW TO INTEGRATE TO PLONE
See ZAAPloneDemo content-type product.
REFRESH INFORMATION
Please DO NOT USE the Zope REFRESH function with ZAttachmentAttribute or Plugins. If you do so, you may get confused with plugins registration (the same plugin may be registered several times, or the plugins list may be truncated at some point).