[Erp5-report] r21443 - in /erp5/trunk/products/ERP5: Document/ tests/
nobody at svn.erp5.org
nobody at svn.erp5.org
Tue Jun 10 04:18:54 CEST 2008
Author: yo
Date: Tue Jun 10 04:18:53 2008
New Revision: 21443
URL: http://svn.erp5.org?rev=21443&view=rev
Log:
Perform substitutions after the conversion, because substituions can be dynamic, thus should not be affected by caches for portal_transformations. (But do we really want to have portal_transformations to cache the results? When caches are implemented at higher levels, such as httpd or erp5 applications, they should be rather useless.)
Modified:
erp5/trunk/products/ERP5/Document/TextDocument.py
erp5/trunk/products/ERP5/tests/testERP5Web.py
Modified: erp5/trunk/products/ERP5/Document/TextDocument.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/TextDocument.py?rev=21443&r1=21442&r2=21443&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/TextDocument.py (original)
+++ erp5/trunk/products/ERP5/Document/TextDocument.py Tue Jun 10 04:18:53 2008
@@ -168,26 +168,6 @@
# check if document has set text_content and convert if necessary
text_content = self.getTextContent()
if text_content is not None:
- # If a method for string substitutions of the text content, perform it.
- # Decode everything into unicode before the substitutions, in order to
- # avoid encoding errors.
- method_id = self.getTextContentSubstitutionMappingMethodId()
- if method_id:
- mapping = guarded_getattr(self, method_id)()
-
- if isinstance(text_content, str):
- text_content = text_content.decode('utf-8')
-
- unicode_mapping = {}
- for k, v in mapping.iteritems():
- if isinstance(v, str):
- v = v.decode('utf-8')
- elif not isinstance(v, unicode):
- v = str(v).decode('utf-8')
- unicode_mapping[k] = v
-
- text_content = Template(text_content).substitute(unicode_mapping)
-
portal_transforms = getToolByName(self, 'portal_transforms')
result = portal_transforms.convertToData(mime_type, text_content,
object=self, context=self,
@@ -198,6 +178,28 @@
LOG('TextDocument.convert', WARNING,
'portal_transforms failed to convert to %s: %r' % (mime_type, self))
result = ''
+
+ # If a method for string substitutions of the text content, perform it.
+ # Decode everything into unicode before the substitutions, in order to
+ # avoid encoding errors.
+ method_id = self.getTextContentSubstitutionMappingMethodId()
+ if method_id:
+ mapping = guarded_getattr(self, method_id)()
+
+ if isinstance(result, str):
+ result = result.decode('utf-8')
+
+ unicode_mapping = {}
+ for k, v in mapping.iteritems():
+ if isinstance(v, str):
+ v = v.decode('utf-8')
+ elif not isinstance(v, unicode):
+ v = str(v).decode('utf-8')
+ unicode_mapping[k] = v
+
+ result = Template(result).substitute(unicode_mapping)
+ # XXX is it better to convert back to str?
+
return mime_type, result
else:
# text_content is not set, return empty string instead of None
Modified: erp5/trunk/products/ERP5/tests/testERP5Web.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/tests/testERP5Web.py?rev=21443&r1=21442&r2=21443&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/tests/testERP5Web.py (original)
+++ erp5/trunk/products/ERP5/tests/testERP5Web.py Tue Jun 10 04:18:53 2008
@@ -389,9 +389,6 @@
document.setTextContentSubstitutionMappingMethodId('getTestSubstitutionMapping')
# Substitutions should occur.
- # XXX purge transformation cache.
- if hasattr(document, '_v_transform_cache'):
- delattr(document, '_v_transform_cache')
self.assertEquals(document.asStrippedHTML(), substituted_content)
klass._getTestSubstitutionMapping = klass.getTestSubstitutionMapping
More information about the Erp5-report
mailing list