[FIX] tools.translate: use `request` to find `cr` and `lang` when other methods fail
Do it only after other direct methods fail, to avoid ignoring a closer environement coming from a calling frame. + Sign CLA Closes #5148
This commit is contained in:
parent
a8b88e4dd4
commit
ea60fed97a
|
@ -0,0 +1,11 @@
|
||||||
|
R. Macedonia, 2015-02-08
|
||||||
|
|
||||||
|
I hereby agree to the terms of the Odoo Individual Contributor License
|
||||||
|
Agreement v1.0.
|
||||||
|
|
||||||
|
I declare that I am authorized and able to make this agreement and sign this
|
||||||
|
declaration.
|
||||||
|
|
||||||
|
Signed,
|
||||||
|
|
||||||
|
Kiril Vangelovski kiril@hacbee.com https://github.com/kirca
|
|
@ -169,7 +169,8 @@ class GettextAlias(object):
|
||||||
return sql_db.db_connect(db_name)
|
return sql_db.db_connect(db_name)
|
||||||
|
|
||||||
def _get_cr(self, frame, allow_create=True):
|
def _get_cr(self, frame, allow_create=True):
|
||||||
# try, in order: cr, cursor, self.env.cr, self.cr
|
# try, in order: cr, cursor, self.env.cr, self.cr,
|
||||||
|
# request.env.cr
|
||||||
if 'cr' in frame.f_locals:
|
if 'cr' in frame.f_locals:
|
||||||
return frame.f_locals['cr'], False
|
return frame.f_locals['cr'], False
|
||||||
if 'cursor' in frame.f_locals:
|
if 'cursor' in frame.f_locals:
|
||||||
|
@ -179,6 +180,11 @@ class GettextAlias(object):
|
||||||
return s.env.cr, False
|
return s.env.cr, False
|
||||||
if hasattr(s, 'cr'):
|
if hasattr(s, 'cr'):
|
||||||
return s.cr, False
|
return s.cr, False
|
||||||
|
try:
|
||||||
|
from openerp.http import request
|
||||||
|
return request.env.cr, False
|
||||||
|
except RuntimeError:
|
||||||
|
pass
|
||||||
if allow_create:
|
if allow_create:
|
||||||
# create a new cursor
|
# create a new cursor
|
||||||
db = self._get_db()
|
db = self._get_db()
|
||||||
|
@ -197,7 +203,7 @@ class GettextAlias(object):
|
||||||
|
|
||||||
def _get_lang(self, frame):
|
def _get_lang(self, frame):
|
||||||
# try, in order: context.get('lang'), kwargs['context'].get('lang'),
|
# try, in order: context.get('lang'), kwargs['context'].get('lang'),
|
||||||
# self.env.lang, self.localcontext.get('lang')
|
# self.env.lang, self.localcontext.get('lang'), request.env.lang
|
||||||
lang = None
|
lang = None
|
||||||
if frame.f_locals.get('context'):
|
if frame.f_locals.get('context'):
|
||||||
lang = frame.f_locals['context'].get('lang')
|
lang = frame.f_locals['context'].get('lang')
|
||||||
|
@ -212,6 +218,12 @@ class GettextAlias(object):
|
||||||
if not lang:
|
if not lang:
|
||||||
if hasattr(s, 'localcontext'):
|
if hasattr(s, 'localcontext'):
|
||||||
lang = s.localcontext.get('lang')
|
lang = s.localcontext.get('lang')
|
||||||
|
if not lang:
|
||||||
|
try:
|
||||||
|
from openerp.http import request
|
||||||
|
lang = request.env.lang
|
||||||
|
except RuntimeError:
|
||||||
|
pass
|
||||||
if not lang:
|
if not lang:
|
||||||
# Last resort: attempt to guess the language of the user
|
# Last resort: attempt to guess the language of the user
|
||||||
# Pitfall: some operations are performed in sudo mode, and we
|
# Pitfall: some operations are performed in sudo mode, and we
|
||||||
|
|
Loading…
Reference in New Issue