Commit a1ed2243 authored by Nicolas Delaby's avatar Nicolas Delaby

Store Conversion in cache

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28984 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d158c530
# -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved. # Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved.
...@@ -201,25 +202,28 @@ class TextDocument(Document, TextContent): ...@@ -201,25 +202,28 @@ class TextDocument(Document, TextContent):
if format == 'raw': if format == 'raw':
return 'text/plain', self.getTextContent() return 'text/plain', self.getTextContent()
mime_type = getToolByName(self, 'mimetypes_registry').lookupExtension('name.%s' % format) mime_type = getToolByName(self, 'mimetypes_registry').lookupExtension('name.%s' % format)
mime_type = str(mime_type)
src_mimetype = self.getTextFormat(DEFAULT_TEXT_FORMAT) src_mimetype = self.getTextFormat(DEFAULT_TEXT_FORMAT)
if not src_mimetype.startswith('text/'): if not src_mimetype.startswith('text/'):
src_mimetype = 'text/%s' % src_mimetype src_mimetype = 'text/%s' % src_mimetype
# check if document has set text_content and convert if necessary # check if document has set text_content and convert if necessary
text_content = self.getTextContent() text_content = self.getTextContent()
if text_content: if text_content:
portal_transforms = getToolByName(self, 'portal_transforms') if not self.hasConversion(format=format):
result = portal_transforms.convertToData(mime_type, text_content, portal_transforms = getToolByName(self, 'portal_transforms')
object=self, context=self, result = portal_transforms.convertToData(mime_type, text_content,
filename=self.getTitleOrId(), object=self, context=self,
mimetype=src_mimetype) filename=self.getTitleOrId(),
if result is None: mimetype=src_mimetype)
raise ConversionError('TextDocument conversion error. ' if result is None:
'portal_transforms failed to convert to %s: %r' % (mime_type, self)) raise ConversionError('TextDocument conversion error. '
'portal_transforms failed to convert to %s: %r' % (mime_type, self))
self.setConversion(result, mime_type, format=format)
else:
mime_type, result = self.getConversion(format=format)
if substitution_method_parameter_dict is None: if substitution_method_parameter_dict is None:
substitution_method_parameter_dict = {} substitution_method_parameter_dict = {}
result = self._substituteTextContent(result, **substitution_method_parameter_dict) result = self._substituteTextContent(result, **substitution_method_parameter_dict)
return mime_type, result return mime_type, result
else: else:
# text_content is not set, return empty string instead of None # text_content is not set, return empty string instead of None
......
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