Another milestone on the road to Zen with Ingeniweb components
Latest version : 2.3

ZAttachmentAttribute

> A system to manage attachments within Zope objects. This product is meant to be used with PloneArticle 2 and PloneExFile 2 versions only. For recent versions of PloneArticle or PloneExFile, please use AttachmentField instead. <

About ZAttachmentAttribute

A system to manage attachments within Zope objects. This product is meant to be used with PloneArticle 2 and PloneExFile 2 versions only. For recent versions of PloneArticle or PloneExFile, please use AttachmentField instead.

ZAttachmentAttribute has been designed by the INGENIWEB team.

ScreenShots

Nothing to say by now.

Readme

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.

WARNING : permissions changing is now deprecated. Sorry for this annoyance :(

  • 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)
  • getPreview() -> return the HTML preview of the attachment, IF AVAILABLE (return None if not)
  • getSmallPreview() -> Same as getPreview if preview length is shorter than MAX_PREVIEW_SIZE, else None. This is useful if you want to quickly display a preview in a page only if it is quite small.
  • 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.

ADDITIONAL PLUGINS

You can write plugins by yourself. You just have to override, in your plugin class (deriving from ZAbstractAttachment), the following properties and/or methods :

  • icon_file => name of the icon file (it must be acquired, for example in a skin)

  • small_icon_file => same as icon_file but for the small icon view

  • content-type => List (of strings) of content_types supported by the class

  • indexAttachment => (method returning a String) index the file

  • getContent => (method returning a loooooong string) of the attachment data.

    The default behaviour is to return self.content

  • isPreviewAvailable => method returning 1 if this attachment can be previewed

    as HTML

  • convertPreview => method returning the HTML preview. It's called generally once per attachment.

You can use some ZAbstractAttachment-defined methods such as :

  • textToHTML(text) => converts a plain-text string into formated HTML

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 tarball...

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).

Download

Released versions

Released versions of ZAttachmentAttribute are available from sourceforge, here. Latest version is 2.3.

CVS version

The CVS contains the latest and historised versions of our source code. In order to get the HEAD branch of ZAttachmentAttribute, use :

cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/ingeniweb co ZAttachmentAttribute
          

You can also browse the CVS with your browser.

Documentation

Readme

Please take time the read the Readme

F.A.Q

Nothing to say by now.

Links

History

ZAttachmentAttribute changes

[v2.3 - 2004-12-27]

  • Used the new release management tool

[v2.21 - 2004-10-01]

  • Removed the __del__ method

[v2.2 - 2004-09-27]

  • Fixed another freezing bug on huge-loaded servers

[v2.12 - 2004-06-03]

  • Fixed Zope 2.7 freezing bug with PloneExFile

[v2.11 - 2004-03-31]

  • Removed stderr printing when the callConverter() has a problem.
  • Better unicode support for plugins

[2004-03-22]

  • Fixed permissions bug
  • Removed permission setting at instanciation-time
  • Improved test plan

[2003-11]

  • added manage_afterAdd, manage_beforeDelete and manage_afterClone For example, without manage_beforeDelete, the method of the container will be called, which can lead to strange bugs. We have to support the interface of SimpleItem or Item to some level here.
  • Added preview support

[2003-08]

  • Added a way of keeping track of indexing pbs

[2003-04-16]

  • Created a __getattr__ method so that it's possible to call the attachment by it's filename in order to comply with buggy browsers. For example, if your object 'toto' has an attachment called 'attach' and your user uploads 'mydoc.doc' inside, you can see the doc by browsing the toto/attach/mydoc.doc URL.

[2003-02-09]

  • Use of the shipped pdf2text with win32
  • Document creation of an Attachment plugin
  • Handle .txt files
  • Handle MS-Word files
  • Handle other file types

[2003-02-07]

  • Moved default attachment plugins to ZAAPlugins product
  • Inverted file and title field in attachement edition skin

[2003-02-05]

  • Moved 'content' variable into ZAbstractAttachment instead of PDFAttachment and ZDummyAttachment
  • Fixed persistancy pb !!!
  • Changed AbstractAttribute choosing from a single MIME type string to a LIST of MIME type strings
  • Fixed uploading content-type guessing (see ZAttachmentAttribute and ZAttachmentRegistry)
  • Created skin for icon files
  • Fixed icons
  • Added AttachmentDemo content type to show how to use it

ZAttachmentAttribute ChangeLog is also available for detailled informations.

Contact