From a1ed2243045c5e27b40f27df72c1d9a0c5d28fe7 Mon Sep 17 00:00:00 2001 From: Nicolas Delaby <nicolas@nexedi.com> Date: Fri, 11 Sep 2009 17:25:28 +0000 Subject: [PATCH] Store Conversion in cache git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28984 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5/Document/TextDocument.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/product/ERP5/Document/TextDocument.py b/product/ERP5/Document/TextDocument.py index a101d55711..ea19c10b6e 100644 --- a/product/ERP5/Document/TextDocument.py +++ b/product/ERP5/Document/TextDocument.py @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- ############################################################################## # # Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved. @@ -201,25 +202,28 @@ class TextDocument(Document, TextContent): if format == 'raw': return 'text/plain', self.getTextContent() mime_type = getToolByName(self, 'mimetypes_registry').lookupExtension('name.%s' % format) + mime_type = str(mime_type) src_mimetype = self.getTextFormat(DEFAULT_TEXT_FORMAT) if not src_mimetype.startswith('text/'): src_mimetype = 'text/%s' % src_mimetype # check if document has set text_content and convert if necessary text_content = self.getTextContent() if text_content: - portal_transforms = getToolByName(self, 'portal_transforms') - result = portal_transforms.convertToData(mime_type, text_content, - object=self, context=self, - filename=self.getTitleOrId(), - mimetype=src_mimetype) - if result is None: - raise ConversionError('TextDocument conversion error. ' - 'portal_transforms failed to convert to %s: %r' % (mime_type, self)) - + if not self.hasConversion(format=format): + portal_transforms = getToolByName(self, 'portal_transforms') + result = portal_transforms.convertToData(mime_type, text_content, + object=self, context=self, + filename=self.getTitleOrId(), + mimetype=src_mimetype) + if result is None: + 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: substitution_method_parameter_dict = {} result = self._substituteTextContent(result, **substitution_method_parameter_dict) - return mime_type, result else: # text_content is not set, return empty string instead of None -- 2.30.9