Commit 237ca283 authored by Nicolas Delaby's avatar Nicolas Delaby

Use mimetypes_registry to guess content_type from filename


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@35228 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b2201cfa
...@@ -27,8 +27,6 @@ ...@@ -27,8 +27,6 @@
# #
############################################################################## ##############################################################################
import mimetypes
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type.Base import WorkflowMethod from Products.ERP5Type.Base import WorkflowMethod
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
...@@ -36,14 +34,10 @@ from Products.ERP5.Document.Document import Document, VALID_TEXT_FORMAT_LIST ...@@ -36,14 +34,10 @@ from Products.ERP5.Document.Document import Document, VALID_TEXT_FORMAT_LIST
from Products.ERP5.Document.Document import ConversionError from Products.ERP5.Document.Document import ConversionError
from Products.ERP5Type.Base import Base, removeIContentishInterface from Products.ERP5Type.Base import Base, removeIContentishInterface
from Products.CMFDefault.File import File as CMFFile from Products.CMFDefault.File import File as CMFFile
from Products.CMFCore.utils import getToolByName
from OFS.Image import Pdata from OFS.Image import Pdata
import cStringIO import cStringIO
# Mixin Import
from Products.ERP5.mixin.cached_convertable import CachedConvertableMixin
mimetypes.init()
def _unpackData(data): def _unpackData(data):
""" """
Unpack Pdata into string Unpack Pdata into string
...@@ -148,13 +142,16 @@ class File(Document, CMFFile): ...@@ -148,13 +142,16 @@ class File(Document, CMFFile):
return self.hasData() return self.hasData()
security.declareProtected(Permissions.ModifyPortalContent, 'guessMimeType') security.declareProtected(Permissions.ModifyPortalContent, 'guessMimeType')
def guessMimeType(self, fname=''): def guessMimeType(self, fname=None):
""" """
get mime type from file name get mime type from file name
""" """
if fname == '': fname = self.getSourceReference() if not fname:
fname = self.getSourceReference()
if fname: if fname:
content_type,enc = mimetypes.guess_type(fname) portal = self.getPortalObject()
content_type = getToolByName(portal, 'mimetypes_registry').\
lookupExtension(fname)
if content_type is not None: if content_type is not None:
self.setContentType(content_type) self.setContentType(content_type)
else: else:
......
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