Commit 244d2051 authored by Tristan Cavelier's avatar Tristan Cavelier

erp5_dms: increase amount of export/conversion choice

by improving Base_getTargetFormatItemList to return a list of all
indirect portal transform conversions.
parent 62a887a6
...@@ -4,40 +4,23 @@ ...@@ -4,40 +4,23 @@
""" """
from Products.ERP5Type.Cache import CachingMethod from Products.ERP5Type.Cache import CachingMethod
def contentTypeMatch(content_type, glob):
if '*' == glob[-1]:
# 'image/png' must match 'image/*'
index = glob.index('*')
return content_type[:index] == glob[:index]
else:
return content_type == glob
portal = context.getPortalObject() portal = context.getPortalObject()
content_type = context.getContentType() content_type = context.getContentType()
def getTargetFormatItemList(content_type): def getTargetFormatItemList(content_type):
# without content type no wayto determine target format # returns [(title, extension), ...]
if content_type is None: if content_type is None:
return [] return []
format_list = [] format_list = []
output_content_type_list = [] available_mimetype_list = portal.portal_transforms.getAvailableTargetMimetypeList(content_type)
for obj in portal.portal_transforms.objectValues(): mimetype_registry = portal.mimetypes_registry
for input in obj.inputs: for available_mimetype in available_mimetype_list:
if contentTypeMatch(content_type, input) and \ mimetype_info_list = mimetype_registry.lookup(available_mimetype)
obj.output not in output_content_type_list and\ for mimetype_info in mimetype_info_list:
obj.output!=content_type:
output_content_type_list.append(obj.output)
for output_content_type in output_content_type_list:
mimetypes_registry_extension_list = portal.mimetypes_registry.lookup(output_content_type)
for mimetypes_registry_extension in mimetypes_registry_extension_list:
title = mimetypes_registry_extension.name()
try: try:
format = mimetypes_registry_extension.extensions[0] format_list.append((mimetype_info.name(), mimetype_info.extensions[0]))
except IndexError: except IndexError:
format = None pass
if format is not None and format not in format_list:
format_list.append((title, format,))
return format_list return format_list
getTargetFormatItemList = CachingMethod(getTargetFormatItemList, getTargetFormatItemList = CachingMethod(getTargetFormatItemList,
......
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