Commit af9fe51c authored by Yusei Tahara's avatar Yusei Tahara

This method is used when a document is exported to external resource as raw...

This method is used when a document is exported to external resource as raw data(for example, attach to an email).


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@21219 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 688528f3
...@@ -35,6 +35,7 @@ from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface ...@@ -35,6 +35,7 @@ from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
from Products.ERP5Type.Cache import CachingMethod from Products.ERP5Type.Cache import CachingMethod
from Products.ERP5.Document.Document import Document from Products.ERP5.Document.Document import Document
from Products.ERP5.Document.Document import ConversionCacheMixin from Products.ERP5.Document.Document import ConversionCacheMixin
from Products.ERP5.Document.Document import ConversionError
from Products.ERP5Type.Base import Base from Products.ERP5Type.Base import Base
from Products.CMFDefault.File import File as CMFFile from Products.CMFDefault.File import File as CMFFile
from zLOG import LOG from zLOG import LOG
...@@ -189,3 +190,43 @@ class File(Document, CMFFile, ConversionCacheMixin): ...@@ -189,3 +190,43 @@ class File(Document, CMFFile, ConversionCacheMixin):
manage_FTPget = CMFFile.manage_FTPget manage_FTPget = CMFFile.manage_FTPget
manage_FTPlist = CMFFile.manage_FTPlist manage_FTPlist = CMFFile.manage_FTPlist
manage_FTPstat = CMFFile.manage_FTPstat 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)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment