merge
This commit is contained in:
commit
715aa650cc
3 files changed
+42
-6
No files matched your search
@@ -22,7 +22,9 @@ OPERATORS = {
|
||||
'not child_of': lambda a, b: True,
|
||||
}
|
||||
|
||||
def locale_part(expression):
|
||||
def locale_part(expression, field_name):
|
||||
if expression == field_name:
|
||||
return 'id'
|
||||
if '.' in expression:
|
||||
fieldname, local = expression.split('.', 1)
|
||||
return local
|
||||
@@ -75,14 +77,14 @@ def eval_domain(domain, context, boolop=operator.and_):
|
||||
return boolop(eval_domain(domain[0], context),
|
||||
eval_domain(domain[1:], context, boolop))
|
||||
|
||||
def localize_domain(domain):
|
||||
def localize_domain(domain, field_name=None):
|
||||
"returns only locale part of domain. eg: langage.code -> code"
|
||||
if domain in ('AND', 'OR', True, False):
|
||||
return domain
|
||||
elif is_leaf(domain):
|
||||
return [locale_part(domain[0])] + domain[1:]
|
||||
return [locale_part(domain[0], field_name)] + domain[1:]
|
||||
else:
|
||||
return [localize_domain(part) for part in domain]
|
||||
return [localize_domain(part, field_name) for part in domain]
|
||||
|
||||
def unlocalize_domain(domain, fieldname):
|
||||
if domain in ('AND', 'OR', True, False):
|
||||
@@ -403,6 +405,17 @@ def test_evaldomain():
|
||||
assert not eval_domain(domain, {'x': 5})
|
||||
assert not eval_domain(domain, {'x': 11})
|
||||
|
||||
def test_localize():
|
||||
domain = [['x', '=', 5]]
|
||||
assert localize_domain(domain) == [['x', '=', 5]]
|
||||
|
||||
domain = [['x', '=', 5], ['x.code', '=', 7]]
|
||||
assert localize_domain(domain, 'x') == [['id', '=', 5], ['code', '=', 7]]
|
||||
|
||||
domain = ['OR', ['AND', ['x', '>', 7], ['x', '<', 15]], ['x.code', '=', 8]]
|
||||
assert localize_domain(domain, 'x') == \
|
||||
['OR', ['AND', ['id', '>', 7], ['id', '<', 15]], ['code', '=', 8]]
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_simple_inversion()
|
||||
test_and_inversion()
|
||||
@@ -414,3 +427,4 @@ if __name__ == '__main__':
|
||||
test_parse()
|
||||
test_simplify()
|
||||
test_evaldomain()
|
||||
test_localize()
|
||||
@@ -394,7 +394,7 @@ class M2OField(CharField):
|
||||
|
||||
def domain_get(self, record):
|
||||
screen_domain, attr_domain = self.domains_get(record)
|
||||
return localize_domain(inverse_leaf(screen_domain)) + attr_domain
|
||||
return localize_domain(inverse_leaf(screen_domain), self.name) + attr_domain
|
||||
|
||||
|
||||
class O2OField(M2OField):
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
#This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
#this repository contains the full copyright notices and license terms.
|
||||
import gettext
|
||||
|
||||
import gtk
|
||||
from interface import WidgetInterface
|
||||
from tryton.common import Tooltips
|
||||
|
||||
_ = gettext.gettext
|
||||
|
||||
class Char(WidgetInterface):
|
||||
"Char"
|
||||
@@ -50,4 +55,21 @@ class Sha(Char):
|
||||
|
||||
def __init__(self, field_name, model_name, window, attrs=None):
|
||||
super(Sha, self).__init__(field_name, model_name, window, attrs=attrs)
|
||||
self.entry.set_visibility(False)
|
||||
self.entry.props.visibility = False
|
||||
|
||||
self.visibility_checkbox = gtk.CheckButton()
|
||||
self.visibility_checkbox.connect('toggled', self.toggle_visibility)
|
||||
Tooltips().set_tip(self.visibility_checkbox, _('Show plain text'))
|
||||
self.widget.pack_start(self.visibility_checkbox, expand=False)
|
||||
|
||||
def _readonly_set(self, value):
|
||||
super(Char, self)._readonly_set(value)
|
||||
self.entry.set_editable(not value)
|
||||
self.visibility_checkbox.props.visible = not value
|
||||
if value:
|
||||
self.widget.set_focus_chain([])
|
||||
else:
|
||||
self.widget.set_focus_chain([self.entry, self.visibility_checkbox])
|
||||
|
||||
def toggle_visibility(self, button):
|
||||
self.entry.props.visibility = not self.entry.props.visibility
|
||||
Reference in new issue
Block a user