diff --git a/product/ERP5OOo/Document/DMSFile.py b/product/ERP5OOo/Document/DMSFile.py index f943b6cf56890356bade679c4345ab0e57667b17..1586d8f236df540032c2022ee1703e2fddcac363 100644 --- a/product/ERP5OOo/Document/DMSFile.py +++ b/product/ERP5OOo/Document/DMSFile.py @@ -35,6 +35,10 @@ from Products.ERP5Type.XMLObject import XMLObject # to overwrite WebDAV methods from Products.CMFDefault.File import File as CMFFile +import mimetypes +mimetypes.init() + + class DMSFile(XMLObject,File): """ Special base class, different from File only in that it can contain things @@ -82,6 +86,16 @@ class DMSFile(XMLObject,File): SearchableText=getSearchableText + security.declareProtected(Permissions.ModifyPortalContent, 'guessMimeType') + def guessMimeType(self,fname=''): + '''get mime type from file name''' + if fname=='':fname=self.getOriginalFilename() + if fname: + content_type,enc=mimetypes.guess_type(fname) + if content_type is not None: + self.content_type=content_type + return content_type + # BG copied from File in case index_html = CMFFile.index_html diff --git a/product/ERP5OOo/Document/OOoDocument.py b/product/ERP5OOo/Document/OOoDocument.py index 85c1578a67be1345adf68056a2c37bdc93290b51..cbcde9b0a9dcb381134c1b1b0b68eee3d3fb3441 100644 --- a/product/ERP5OOo/Document/OOoDocument.py +++ b/product/ERP5OOo/Document/OOoDocument.py @@ -36,10 +36,12 @@ from Products.ERP5Type.Cache import CachingMethod from Products.ERP5.Document.File import File from Products.ERP5Type.XMLObject import XMLObject from DateTime import DateTime -import xmlrpclib, base64 +import xmlrpclib, base64, mimetypes # to overwrite WebDAV methods from Products.CMFDefault.File import File as CMFFile +mimetypes.init() + enc=base64.encodestring dec=base64.decodestring @@ -495,6 +497,19 @@ class OOoDocument(XMLObject,File): s+='</table>' return s + # this will go out after refactoring (will be inherited from DMS File + # and eventually from File + security.declareProtected(Permissions.ModifyPortalContent, 'guessMimeType') + def guessMimeType(self,fname=''): + '''get mime type from file name''' + if fname=='':fname=self.getOriginalFilename() + if fname: + content_type,enc=mimetypes.guess_type(fname) + if content_type is not None: + self.content_type=content_type + return content_type + + # make sure to call the right edit methods _edit=File._edit edit=File.edit