Commit c827410b authored by Tristan Cavelier's avatar Tristan Cavelier

hack to handle mimetypes quickly

parent a985974c
......@@ -37,6 +37,11 @@ from base64 import b64decode
def keyNameToOption(key_name, prefix=""):
return "--" + prefix + key_name.replace("_", "-")
def hackMimetypeToFormatTRISTAN(mimetype):
if mimetype in ("application/x-pdf-report", "application/pdf"): return "pdf"
if mimetype in ("text/html",): return "html"
return mimetype
class Handler(object):
"""ImageMagic Handler is used to handler images."""
......@@ -44,6 +49,7 @@ class Handler(object):
def __init__(self, base_folder_url, data, source_format, **kw):
""" Load pdf document """
source_format = hackMimetypeToFormatTRISTAN(source_format)
self.base_folder_url = base_folder_url
self.file = File(base_folder_url, data, source_format)
self.environment = kw.get("env", {})
......@@ -62,6 +68,7 @@ class Handler(object):
def convert(self, destination_format=None, **kw):
"""Convert a image"""
destination_format = hackMimetypeToFormatTRISTAN(destination_format)
logger.debug("wkhtmltopdf convert: %s > %s" % (self.file.source_format, destination_format))
output_path = self.makeTempFile(destination_format)
command = self.makeWkhtmltopdfCommandList(
......
......@@ -49,8 +49,14 @@ def getHandlerClass(source_format, destination_format, mimetype_registry,
handler_dict):
"""Select handler according to source_format and destination_format
"""
source_mimetype = mimetypes.types_map.get('.%s' % source_format, "*")
destination_mimetype = mimetypes.types_map.get('.%s' % destination_format, "*")
if "/" in source_format:
source_mimetype = source_format
else:
source_mimetype = mimetypes.types_map.get('.%s' % source_format, "*")
if "/" in destination_format:
destination_mimetype = destination_format
else:
destination_mimetype = mimetypes.types_map.get('.%s' % destination_format, "*")
for pattern in mimetype_registry:
registry_list = pattern.split()
if fnmatch(source_mimetype, registry_list[0]) and \
......
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