[Erp5-report] r21219 - /erp5/trunk/products/ERP5/Document/File.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Thu May 29 13:58:01 CEST 2008
Author: yusei
Date: Thu May 29 13:57:56 2008
New Revision: 21219
URL: http://svn.erp5.org?rev=21219&view=rev
Log:
This method is used when a document is exported to external resource as raw data(for example, attach to an email).
Modified:
erp5/trunk/products/ERP5/Document/File.py
Modified: erp5/trunk/products/ERP5/Document/File.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/File.py?rev=21219&r1=21218&r2=21219&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/File.py (original)
+++ erp5/trunk/products/ERP5/Document/File.py Thu May 29 13:57:56 2008
@@ -35,6 +35,7 @@
from Products.ERP5Type.Cache import CachingMethod
from Products.ERP5.Document.Document import Document
from Products.ERP5.Document.Document import ConversionCacheMixin
+from Products.ERP5.Document.Document import ConversionError
from Products.ERP5Type.Base import Base
from Products.CMFDefault.File import File as CMFFile
from zLOG import LOG
@@ -189,3 +190,43 @@
manage_FTPget = CMFFile.manage_FTPget
manage_FTPlist = CMFFile.manage_FTPlist
manage_FTPstat = CMFFile.manage_FTPstat
+
+ security.declareProtected(Permissions.AccessContentsInformation, 'getMimeTypeAndContent')
+ def getMimeTypeAndContent(self):
+ """This method returns a tuple which contains mimetype and content."""
+ from Products.ERP5.Document.EmailDocument import MimeTypeException
+ # return a tuple (mime_type, data)
+ mime_type = None
+ content = None
+
+ # WARNING - this could fail since getContentType
+ # is not (yet) part of Document API
+ if getattr(self, 'getContentType', None) is not None:
+ mime_type = self.getContentType()
+ elif getattr(self, 'getTextFormat', None) is not None:
+ mime_type = self.getTextFormat()
+ else:
+ raise ValueError, "Cannot find mimetype of the document."
+
+ if mime_type is not None:
+ try:
+ mime_type, content = self.convert(mime_type)
+ except ConversionError:
+ mime_type = self.getBaseContentType()
+ content = self.getBaseData()
+ except (NotImplementedError, MimeTypeException):
+ pass
+
+ if content is None:
+ if getattr(self, 'getTextContent', None) is not None:
+ content = self.getTextContent()
+ elif getattr(self, 'getData', None) is not None:
+ content = self.getData()
+ elif getattr(self, 'getBaseData', None) is not None:
+ content = self.getBaseData()
+
+ if content and not isinstance(content, str):
+ content = str(content)
+
+ return (mime_type, content)
+
More information about the Erp5-report
mailing list