Use instance context in translated descriptor of Selection field
It is more expected from the translated descriptor to return translation in the language from the instance instead of the current context. issue5028 review15701002
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
* Use instance context in translated descriptor of Selection
|
||||
|
||||
Version 3.8.0 - 2015-11-02
|
||||
* Bug fixes (see mercurial logs for details)
|
||||
* Add test for all field methods
|
||||
|
||||
@@ -439,7 +439,8 @@ Instance methods:
|
||||
.. method:: Selection.translated([name])
|
||||
|
||||
Returns a descriptor for the translated value of the field. The descriptor
|
||||
must be used on the same class as the field.
|
||||
must be used on the same class as the field. It will use the language
|
||||
defined in the context of the instance accessed.
|
||||
|
||||
Reference
|
||||
---------
|
||||
|
||||
@@ -5,6 +5,7 @@ import warnings
|
||||
from sql.conditionals import Case
|
||||
|
||||
from ... import backend
|
||||
from ...transaction import Transaction
|
||||
from .field import Field, SQLType
|
||||
|
||||
|
||||
@@ -82,7 +83,9 @@ class TranslatedSelection(object):
|
||||
def __get__(self, inst, cls):
|
||||
if inst is None:
|
||||
return self
|
||||
selection = dict(cls.fields_get([self.name])[self.name]['selection'])
|
||||
with Transaction().set_context(getattr(inst, '_context', {})):
|
||||
selection = dict(
|
||||
cls.fields_get([self.name])[self.name]['selection'])
|
||||
value = getattr(inst, self.name)
|
||||
# None and '' are equivalent
|
||||
if value is None or value == '':
|
||||
|
||||
Reference in New Issue
Block a user