Commit 0370336b authored by Julien Muchembled's avatar Julien Muchembled

ERP5Type.Message: fix retrieval of portal

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@39217 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 77cece36
...@@ -179,8 +179,6 @@ class TestPerson(ERP5TypeTestCase): ...@@ -179,8 +179,6 @@ class TestPerson(ERP5TypeTestCase):
def testPreferenceInteractionWorkflow(self): def testPreferenceInteractionWorkflow(self):
""" when setting reference, a script create preference is """ when setting reference, a script create preference is
called by activities, check this behavior. """ called by activities, check this behavior. """
if not run:
return
person_module = self.getPersonModule() person_module = self.getPersonModule()
title = "Séb" title = "Séb"
person = person_module.newContent(portal_type='Person', title=title) person = person_module.newContent(portal_type='Person', title=title)
......
...@@ -84,6 +84,8 @@ except ImportError: ...@@ -84,6 +84,8 @@ except ImportError:
getGlobalTranslationService = GlobalTranslationService getGlobalTranslationService = GlobalTranslationService
translation_service_translate = getGlobalTranslationService().translate
from Products.ERP5Type import Globals from Products.ERP5Type import Globals
from cPickle import dumps, loads from cPickle import dumps, loads
...@@ -135,31 +137,28 @@ class Message(Persistent): ...@@ -135,31 +137,28 @@ class Message(Persistent):
the return value is a string object. If it is a unicode object, the return value is a string object. If it is a unicode object,
the return value is a unicode object. the return value is a unicode object.
""" """
request = Globals.get_request()
if request is not None:
context = request['PARENTS'][0]
translation_service = getGlobalTranslationService()
message = self.message message = self.message
if self.domain is None or request is None or translation_service is None : if self.domain is None:
# Map the translated string with given parameters # Map the translated string with given parameters
if type(self.mapping) is type({}): if type(self.mapping) is dict:
if isinstance(message, unicode) : if isinstance(message, unicode) :
message = message.encode('utf-8') message = message.encode('utf-8')
message = Template(message).substitute(self.mapping) message = Template(message).substitute(self.mapping)
else: else:
translated_message = translation_service.translate( from Products.ERP5.ERP5Site import getSite
translated_message = translation_service_translate(
self.domain, self.domain,
self.message, message,
mapping=self.mapping, mapping=self.mapping,
context=context, context=getSite(),
default=self.default) default=self.default)
if translated_message is not None: if translated_message is not None:
message = translated_message message = translated_message
if isinstance(self.message, str) and isinstance(message, unicode): if isinstance(self.message, str):
if isinstance(message, unicode):
message = message.encode('utf-8') message = message.encode('utf-8')
elif isinstance(self.message, unicode) and isinstance(message, str): elif isinstance(message, str):
message = message.decode('utf-8') message = message.decode('utf-8')
return message return message
......
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