Updated python converter backend, document model and staging module to use the new get_mimetype API
This commit is contained in:
@@ -25,7 +25,7 @@ class ConverterClass(ConverterBase):
|
||||
def get_page_count(self, input_filepath):
|
||||
page_count = 1
|
||||
|
||||
mimetype, encoding = get_mimetype(input_filepath)
|
||||
mimetype, encoding = get_mimetype(open(input_filepath, 'rb'), input_filepath)
|
||||
if mimetype == 'application/pdf':
|
||||
# If file is a PDF open it with slate to determine the page
|
||||
# count
|
||||
@@ -50,7 +50,7 @@ class ConverterClass(ConverterBase):
|
||||
|
||||
def convert_file(self, input_filepath, output_filepath, transformations=None, page=DEFAULT_PAGE_NUMBER, file_format=DEFAULT_FILE_FORMAT):
|
||||
tmpfile = None
|
||||
mimetype, encoding = get_mimetype(input_filepath)
|
||||
mimetype, encoding = get_mimetype(open(input_filepath, 'rb'), input_filepath)
|
||||
if mimetype == 'application/pdf' and USE_GHOSTSCRIPT:
|
||||
# If file is a PDF open it with ghostscript and convert it to
|
||||
# TIFF
|
||||
|
||||
@@ -17,7 +17,7 @@ from converter.api import get_page_count
|
||||
from converter.api import get_available_transformations_choices
|
||||
from converter.api import convert
|
||||
from converter.exceptions import UnknownFileFormat, UnkownConvertError
|
||||
from mimetype.api import get_document_mimetype, get_icon_file_path, \
|
||||
from mimetype.api import get_mimetype, get_icon_file_path, \
|
||||
get_error_icon_file_path
|
||||
|
||||
from documents.conf.settings import CHECKSUM_FUNCTION
|
||||
@@ -135,7 +135,7 @@ class Document(models.Model):
|
||||
"""
|
||||
if self.exists():
|
||||
try:
|
||||
self.file_mimetype, self.mime_encoding = get_document_mimetype(self)
|
||||
self.file_mimetype, self.mime_encoding = get_mimetype(self.open(), self.get_fullname())
|
||||
except:
|
||||
self.file_mimetype = u''
|
||||
self.file_mime_encoding = u''
|
||||
|
||||
@@ -138,6 +138,7 @@ class StagingFile(object):
|
||||
try:
|
||||
return convert(self.filepath, size=size, cleanup_files=False, transformations=transformations)
|
||||
except UnknownFileFormat:
|
||||
return get_icon_file_path(get_mimetype(self.filepath))
|
||||
mimetype, encoding = get_mimetype(open(self.filepath, 'rb'), self.filepath)
|
||||
return get_icon_file_path(mimetype)
|
||||
except UnkownConvertError:
|
||||
return get_error_icon_file_path()
|
||||
|
||||
Reference in New Issue
Block a user