File: README.txt

package info (click to toggle)
zope-zattachmentattribute 2.21-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 324 kB
  • ctags: 238
  • sloc: sh: 1,365; python: 1,311; makefile: 89
file content (147 lines) | stat: -rw-r--r-- 5,308 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147


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.

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