9c0deb80ae1494d65ce7585ca63fe809f75cbf44
1 ##parameters=command, path, file='', Type='', redirUrl=''
3 from Products
.CMFCore
.utils
import getToolByName
5 def replaceXMLEntities(text
) :
6 for c
, ent
in (('<', '<'), ('>', '>'), ('&', '&')) :
7 text
= text
.replace(c
, ent
)
10 utool
= getToolByName(context
, 'portal_url')
11 atool
= getToolByName(context
, 'portal_attachment')
13 portal
= utool
.getPortalObject()
16 path
= path
.strip('/')
19 path
= path
.strip('/')
21 for name
in path
.split('/') :
22 ob
= getattr(ob
, name
)
25 attachments
= atool
.getAttachmentsFor(ob
)
26 attachments
= attachments
.objectValues()
29 for o
in attachments
:
30 size
= o
.getThumbnailSize()
31 row
= '<row previewUrl="%(previewUrl)s" url="%(url)s" meta_type="%(meta_type)s" width="%(width)d" height="%(height)d">%(title)s</row>' % {
32 'previewUrl' : '%s/getThumbnail' % o
.absolute_url(),
33 'url' : 'attachments/%s' % o
.getId(),
34 'meta_type' : o
.meta_type
,
35 'title' : replaceXMLEntities(o
.title_or_id()),
36 'width' : size
['width'],
37 'height' : size
['height']
42 if command
== 'upload' :
43 atool
.uploadAttachmentFor(ob
, file, typeName
=Type
)
44 return context
.REQUEST
.RESPONSE
.redirect(redirUrl
);
47 ob
= context
.restrictedTraverse(path
)
48 parent
= ob
.getParentNode()
49 parent
.manage_delObjects(ob
.getId())
53 context
.REQUEST
.RESPONSE
.setHeader('content-type', 'text/xml; charset=utf-8')