Commit 15ab3e27 authored by Bartek Górny's avatar Bartek Górny

additional method for setting content_type of an object created by a script

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@9187 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 5cf20974
......@@ -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
......
......@@ -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
......
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