Implémentation envoi d'images.
[Plinn.git] / AttachmentTool.py
index 4df5a3f..979148d 100644 (file)
@@ -30,6 +30,7 @@ from OFS.SimpleItem import SimpleItem
 from OFS.Folder import Folder
 from OFS.Image import File, cookId
 from zExceptions import Unauthorized
+from zExceptions import BadRequest
 from Products.Photo import Photo
 from Products.CMFCore.utils import UniqueObject, getToolByName, getUtilityByInterfaceName
 from Products.CMFCore.permissions import ModifyPortalContent
@@ -114,6 +115,16 @@ class AttachmentContainer (Folder):
     def __init__(self):
         self.id = 'attachments'
 
+    security.declarePrivate('checkIdAvailable')
+    def checkIdAvailable(self, id):
+        try:
+            self._checkId(id)
+        except BadRequest:
+            return False
+        else:
+            return True
+
+
     security.declareProtected(ModifyPortalContent, 'put_upload')
     def put_upload(self, REQUEST, RESPONSE):
         """ Upload a content thru webdav put method.
@@ -174,7 +185,16 @@ class AttachmentContainer (Folder):
         ob.PUT(REQUEST, RESPONSE)
         RESPONSE.setStatus(httpRespCode)
         RESPONSE.setHeader('Content-Type', 'text/xml;;charset=utf-8')
-        return '<element id="%s" title="%s"/>' % (ob.getId(), escape(ob.title_or_id()))
+        if ob.meta_type == 'File' :
+            return '<element id="%s" title="%s"/>' % (ob.getId(), escape(ob.title_or_id()))
+        elif ob.meta_type == 'Photo' :
+            width, height = ob.getResizedImageSize(size=(310, 310))
+            return '<element src="%(src)s" title="%(title)s" width="%(width)d" height="%(height)d"/>' % \
+                {'src' : 'attachments/%s/getResizedImage?size=%d_%d' % (ob.getId(), width, height),
+                 'title' : escape(ob.title_or_id()),
+                 'width' : width,
+                 'height' : height
+                 }
 
 
 InitializeClass(AttachmentContainer)
\ No newline at end of file