Commit e915eff8 authored by Jérome Perrin's avatar Jérome Perrin

Fix translated category accessors

Translated property accessor accessor accidentally changed to return
on python2 unicode for translated messages and str for non translated
messages in a17bb910 

To make it worse, CMFCategory's Renderer was swallowing exceptions.

This restores translated accessors behavior and changes Renderer to
let exceptions propagate

See merge request !1629
parents eef80b9e 941eba51
Pipeline #21532 failed with stage
in 0 seconds
......@@ -171,14 +171,7 @@ class Renderer(Filter):
if self.display_method is not None:
label = self.display_method(value)
elif self.display_id is not None:
try:
label = value.getProperty(self.display_id)
except ConflictError:
raise
except:
LOG('CMFCategory', PROBLEM, 'Renderer was unable to call %s on %s'
% (self.display_id, value.getRelativeUrl()))
label = None
label = value.getProperty(self.display_id)
else:
label = None
# Get the url.
......
# coding:utf-8
##############################################################################
#
# Copyright (c) 2004 Nexedi SARL and Contributors. All Rights Reserved.
......@@ -26,6 +27,7 @@
#
##############################################################################
import mock
from collections import deque
import unittest
......@@ -756,6 +758,60 @@ class TestCMFCategory(ERP5TypeTestCase):
whitespace_number = self.portal.portal_preferences.getPreferredWhitespaceNumberForChildItemIndentation()
self.assertEqual(NBSP_UTF8 * whitespace_number + 'The Sub Title', sub_cat.getIndentedTitle())
def test_getCategoryChildTranslatedXItemList(self):
base_cat = self.getCategoryTool().newContent(portal_type='Base Category')
cat = base_cat.newContent(
portal_type='Category', id='the_id', title='The Title')
cat.newContent(
portal_type='Category', id='the_sub_id', title='The Sub Title')
default_gettext = self.portal.Localizer.erp5_content.gettext
def gettext(message, **kw):
if message == 'The Sub Title':
return u'The Süb Tïtle'
assert message != u'The Süb Tïtle'
return default_gettext(message, **kw)
with mock.patch.object(
self.portal.Localizer.erp5_content.__class__,
'gettext',
side_effect=gettext), \
mock.patch.object(
self.portal.portal_preferences.__class__,
'getPreferredWhitespaceNumberForChildItemIndentation',
return_value=2):
self.assertEqual(
base_cat.getCategoryChildIndentedTitleItemList(),
[['', ''],
['The Title', 'the_id'],
['\xc2\xa0\xc2\xa0The Sub Title', 'the_id/the_sub_id']],
)
self.assertEqual(
base_cat.getCategoryChildTranslatedIndentedTitleItemList(),
[['', ''],
['The Title', 'the_id'],
['\xc2\xa0\xc2\xa0The S\xc3\xbcb T\xc3\xaftle', 'the_id/the_sub_id']],
)
self.assertEqual(
base_cat.getCategoryChildTranslatedCompactTitleItemList(),
[['', ''],
['The Title', 'the_id'],
['The S\xc3\xbcb T\xc3\xaftle', 'the_id/the_sub_id']],
)
self.assertEqual(
base_cat.getCategoryChildTranslatedLogicalPathItemList(),
[['', ''],
['The Title', 'the_id'],
['The Title/The S\xc3\xbcb T\xc3\xaftle', 'the_id/the_sub_id']],
)
self.assertEqual(
base_cat.getCategoryChildTranslatedCompactLogicalPathItemList(),
[['', ''],
['The Title', 'the_id'],
['The Title/The S\xc3\xbcb T\xc3\xaftle', 'the_id/the_sub_id']],
)
def test_CategoryChildTitleItemListFilterNodeFilterLeave(self):
base_cat = self.getCategoryTool().newContent(portal_type='Base Category')
base_cat.newContent(
......
......@@ -26,6 +26,7 @@
#
##############################################################################
from six import ensure_text
from zLOG import LOG
from Products.ERP5Type.PsycoWrapper import psyco
from Acquisition import aq_base
......@@ -33,6 +34,7 @@ from Acquisition import aq_base
from Products.ERP5Type.Accessor.Base import func_code, ATTRIBUTE_PREFIX, evaluateTales, Getter as BaseGetter, Method
from Products.ERP5Type.Accessor import Accessor, AcquiredProperty
from Products.ERP5Type.Accessor.TypeDefinition import type_definition
from Products.ERP5Type.Utils import unicode2str
TRANSLATION_DOMAIN_CONTENT_TRANSLATION = 'content_translation'
......@@ -85,9 +87,9 @@ class TranslatedPropertyGetter(BaseGetter):
localizer = instance.getPortalObject().Localizer
message_catalog = getattr(localizer, domain, None)
if message_catalog is not None:
return message_catalog.gettext(value, lang=self._language)
else:
return value
return unicode2str(
message_catalog.gettext(ensure_text(value), lang=self._language))
return value
psyco.bind(__call__)
......
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