diff --git a/product/CMFActivity/ActivityTool.py b/product/CMFActivity/ActivityTool.py index 121f0d4e9009465ae753ed20d7cc530d13a15d74..f24aa7b1c17ddbd4b44791d8f99b108d68bc68dd 100644 --- a/product/CMFActivity/ActivityTool.py +++ b/product/CMFActivity/ActivityTool.py @@ -54,6 +54,7 @@ from zExceptions import ExceptionFormatter from BTrees.OIBTree import OIBTree from Zope2 import app from Products.ERP5Type.UnrestrictedMethod import PrivilegedUser +from zope.site.hooks import setSite try: from Products import iHotfix @@ -306,6 +307,10 @@ class Message(BaseMessage): self.setExecutionState(MESSAGE_NOT_EXECUTABLE, exc_info, context=activity_tool) else: + # Store site info + portal = getattr(obj, 'getPortalObject', lambda:None)() + if portal is not None: + setSite(portal) if activity_tool.activity_timing_log: result = activity_timing_method(method, self.args, self.kw) else: diff --git a/product/ERP5Type/tests/testLocalizer.py b/product/ERP5Type/tests/testLocalizer.py index a9130619f0b3d42c2ab62a2874c4a77749060858..ada7eef091d0a061873d436977f175b1c433a91b 100644 --- a/product/ERP5Type/tests/testLocalizer.py +++ b/product/ERP5Type/tests/testLocalizer.py @@ -29,7 +29,9 @@ import unittest from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase +from Products.ERP5Type.tests.utils import createZODBPythonScript from Persistence import PersistentMapping +from zope.site.hooks import setSite class TestLocalizer(ERP5TypeTestCase): def afterSetUp(self): @@ -38,6 +40,12 @@ class TestLocalizer(ERP5TypeTestCase): self.message_catalog.add_language('fr') self.message_catalog._messages.clear() + def beforeTearDown(self): + tmp_obj = getattr(self, 'tmp_obj', None) + if tmp_obj is not None: + tmp_obj.aq_parent.manage_delObjects(ids=[tmp_obj.getId(),]) + self.tic() + def test_non_ascii_msgid(self): self.assertEqual(self.portal.Base_translateString('This is 1鈧�.', lang='fr'), "This is 1鈧�.") @@ -99,6 +107,26 @@ class TestLocalizer(ERP5TypeTestCase): self.assertFalse('This is 1鈧�.' in self.message_catalog._messages) self.assertTrue(u'This is 1鈧�.' in self.message_catalog._messages) + def test_localizer_transle_in_activity(self): + self.assertEqual(self.portal.Base_translateString('This is 1鈧�.', lang='fr'), + "This is 1鈧�.") + self.message_catalog.message_edit(u'This is 1鈧�.', 'fr', u"C'est 1鈧�.", '') + skin = self.portal.portal_skins.custom + createZODBPythonScript( + skin, 'test_activity', '', + "context.setComment(context.Base_translateString('This is 1鈧�.', lang='fr'))", + ) + tmp_obj = self.portal.portal_templates.newContent() + self.tic() + tmp_obj.activate().test_activity() + # here we don't call self.tic() that calls self.getPortal() that + # reinvoke setSite(portal). + setSite() + self.commit() + while self.portal.portal_activities.getMessageList(): + self.portal.portal_activities.process_timer(None, None) + self.assertEquals(tmp_obj.getComment(), "C'est 1鈧�.") + def test_suite(): suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(TestLocalizer))