Commit 3c3ffc9b authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

fix the issue 'Localizer.translate() does not work when it is called in activity'.

parent 5e9fa9d0
...@@ -54,6 +54,7 @@ from zExceptions import ExceptionFormatter ...@@ -54,6 +54,7 @@ from zExceptions import ExceptionFormatter
from BTrees.OIBTree import OIBTree from BTrees.OIBTree import OIBTree
from Zope2 import app from Zope2 import app
from Products.ERP5Type.UnrestrictedMethod import PrivilegedUser from Products.ERP5Type.UnrestrictedMethod import PrivilegedUser
from zope.site.hooks import setSite
try: try:
from Products import iHotfix from Products import iHotfix
...@@ -306,6 +307,10 @@ class Message(BaseMessage): ...@@ -306,6 +307,10 @@ class Message(BaseMessage):
self.setExecutionState(MESSAGE_NOT_EXECUTABLE, exc_info, self.setExecutionState(MESSAGE_NOT_EXECUTABLE, exc_info,
context=activity_tool) context=activity_tool)
else: else:
# Store site info
portal = getattr(obj, 'getPortalObject', lambda:None)()
if portal is not None:
setSite(portal)
if activity_tool.activity_timing_log: if activity_tool.activity_timing_log:
result = activity_timing_method(method, self.args, self.kw) result = activity_timing_method(method, self.args, self.kw)
else: else:
......
...@@ -29,7 +29,9 @@ ...@@ -29,7 +29,9 @@
import unittest import unittest
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.utils import createZODBPythonScript
from Persistence import PersistentMapping from Persistence import PersistentMapping
from zope.site.hooks import setSite
class TestLocalizer(ERP5TypeTestCase): class TestLocalizer(ERP5TypeTestCase):
def afterSetUp(self): def afterSetUp(self):
...@@ -38,6 +40,12 @@ class TestLocalizer(ERP5TypeTestCase): ...@@ -38,6 +40,12 @@ class TestLocalizer(ERP5TypeTestCase):
self.message_catalog.add_language('fr') self.message_catalog.add_language('fr')
self.message_catalog._messages.clear() 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): def test_non_ascii_msgid(self):
self.assertEqual(self.portal.Base_translateString('This is 1€.', lang='fr'), self.assertEqual(self.portal.Base_translateString('This is 1€.', lang='fr'),
"This is 1€.") "This is 1€.")
...@@ -99,6 +107,26 @@ class TestLocalizer(ERP5TypeTestCase): ...@@ -99,6 +107,26 @@ class TestLocalizer(ERP5TypeTestCase):
self.assertFalse('This is 1€.' in self.message_catalog._messages) self.assertFalse('This is 1€.' in self.message_catalog._messages)
self.assertTrue(u'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(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestLocalizer)) suite.addTest(unittest.makeSuite(TestLocalizer))
......
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