From 9c80571ba889e762fe574c57f5e08b693e907703 Mon Sep 17 00:00:00 2001 From: Jean-Paul Smets <jp@nexedi.com> Date: Sun, 19 Apr 2009 12:18:47 +0000 Subject: [PATCH] title_or_is not en ERP5 method. Use getTitleOrId. Also, not raising an error in case of portal_transforms error is wrong since it pollutes the cache with empty strings. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@26497 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5/Document/PDFDocument.py | 10 ++++------ product/ERP5/Document/TextDocument.py | 12 +++++------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/product/ERP5/Document/PDFDocument.py b/product/ERP5/Document/PDFDocument.py index cd192a0332..835701e8a3 100644 --- a/product/ERP5/Document/PDFDocument.py +++ b/product/ERP5/Document/PDFDocument.py @@ -33,7 +33,7 @@ from Products.CMFCore.utils import getToolByName from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface from Products.ERP5Type.Cache import CachingMethod from Products.ERP5.Document.Image import Image -from Products.ERP5.Document.Document import ConversionCacheMixin +from Products.ERP5.Document.Document import ConversionCacheMixin, ConversionError from Products.ERP5.Document.File import _unpackData from zLOG import LOG, WARNING @@ -161,13 +161,11 @@ class PDFDocument(Image, ConversionCacheMixin): portal_transforms = getToolByName(self, 'portal_transforms') result = portal_transforms.convertToData(mime_type, content, context=self, - filename=self.title_or_id(), + filename=self.getTitleOrId(), mimetype=src_mimetype) if result is None: - # portal_transforms fails to convert. - LOG('TextDocument.convert', WARNING, - 'portal_transforms failed to convert to %s: %r' % (mime_type, self)) - result = '' + raise ConversionError('PDFDocument conversion error. ' + 'portal_transforms failed to convert to %s: %r' % (mime_type, self)) text += result return text diff --git a/product/ERP5/Document/TextDocument.py b/product/ERP5/Document/TextDocument.py index fc97666984..42b446f917 100644 --- a/product/ERP5/Document/TextDocument.py +++ b/product/ERP5/Document/TextDocument.py @@ -33,7 +33,7 @@ from Products.ERP5Type.Base import WorkflowMethod from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import _setCacheHeaders, _ViewEmulator from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface -from Products.ERP5.Document.Document import Document +from Products.ERP5.Document.Document import Document, ConversionError from Products.ERP5Type.WebDAVSupport import TextContent from Products.CMFDefault.utils import isHTMLSafe import re @@ -209,17 +209,15 @@ class TextDocument(Document, TextContent): src_mimetype = 'text/%s' % src_mimetype # check if document has set text_content and convert if necessary text_content = self.getTextContent() - if text_content is not None: + if text_content: portal_transforms = getToolByName(self, 'portal_transforms') result = portal_transforms.convertToData(mime_type, text_content, object=self, context=self, - filename=self.title_or_id(), + filename=self.getTitleOrId(), mimetype=src_mimetype) if result is None: - # portal_transforms fails to convert. - LOG('TextDocument.convert', WARNING, - 'portal_transforms failed to convert to %s: %r' % (mime_type, self)) - result = '' + raise ConversionError('TextDocument conversion error. ' + 'portal_transforms failed to convert to %s: %r' % (mime_type, self)) if substitution_method_parameter_dict is None: substitution_method_parameter_dict = {} -- 2.30.9