Set completion action following the access right
The actions of completion are not always connected or allowed to the user. So get_completion gets two optional parameter for the search and create action, they are set according to the access right of the user by each widget. issue4535 review10871002
This commit is contained in:
1 parent
098f661740
commit
f4ff6ca934
6 files changed
+23
-10
No files matched your search
@@ -11,15 +11,17 @@ from tryton.exceptions import TrytonServerError, TrytonError
|
||||
_ = gettext.gettext
|
||||
|
||||
|
||||
def get_completion():
|
||||
def get_completion(search=True, create=True):
|
||||
"Return a EntryCompletion"
|
||||
completion = gtk.EntryCompletion()
|
||||
completion.set_match_func(lambda *a: True)
|
||||
completion.set_model(gtk.ListStore(str, int))
|
||||
completion.set_text_column(0)
|
||||
completion.props.popup_set_width = False
|
||||
completion.insert_action_markup(0, _('<i>Search...</i>'))
|
||||
completion.insert_action_markup(1, _('<i>Create...</i>'))
|
||||
if search:
|
||||
completion.insert_action_markup(0, _('<i>Search...</i>'))
|
||||
if create:
|
||||
completion.insert_action_markup(1, _('<i>Create...</i>'))
|
||||
return completion
|
||||
|
||||
|
||||
|
||||
@@ -333,7 +333,7 @@ class DictWidget(Widget):
|
||||
hbox.pack_start(self.wid_text, expand=True, fill=True)
|
||||
|
||||
if int(self.attrs.get('completion', 1)):
|
||||
self.wid_completion = get_completion()
|
||||
self.wid_completion = get_completion(search=False, create=False)
|
||||
self.wid_completion.connect('match-selected',
|
||||
self._completion_match_selected)
|
||||
self.wid_text.set_completion(self.wid_completion)
|
||||
|
||||
@@ -44,7 +44,9 @@ class Many2Many(Widget):
|
||||
hbox.pack_start(self.wid_text, expand=True, fill=True)
|
||||
|
||||
if int(self.attrs.get('completion', 1)):
|
||||
self.wid_completion = get_completion()
|
||||
self.wid_completion = get_completion(
|
||||
create=self.attrs.get('create', True)
|
||||
and common.MODELACCESS[self.attrs['relation']]['create'])
|
||||
self.wid_completion.connect('match-selected',
|
||||
self._completion_match_selected)
|
||||
self.wid_completion.connect('action-activated',
|
||||
|
||||
@@ -39,7 +39,9 @@ class Many2One(Widget):
|
||||
self.focus_out = True
|
||||
|
||||
if int(self.attrs.get('completion', 1)):
|
||||
self.wid_completion = get_completion()
|
||||
self.wid_completion = get_completion(
|
||||
search=self.read_access,
|
||||
create=self.create_access)
|
||||
self.wid_completion.connect('match-selected',
|
||||
self._completion_match_selected)
|
||||
self.wid_completion.connect('action-activated',
|
||||
|
||||
@@ -49,7 +49,10 @@ class One2Many(Widget):
|
||||
hbox.pack_start(self.wid_text, expand=True, fill=True)
|
||||
|
||||
if int(self.attrs.get('completion', 1)):
|
||||
self.wid_completion = get_completion()
|
||||
access = common.MODELACCESS[attrs['relation']]
|
||||
self.wid_completion = get_completion(
|
||||
search=access['read'] and access['write'],
|
||||
create=attrs.get('create', True) and access['create'])
|
||||
self.wid_completion.connect('match-selected',
|
||||
self._completion_match_selected)
|
||||
self.wid_completion.connect('action-activated',
|
||||
@@ -288,7 +291,6 @@ class One2Many(Widget):
|
||||
self._position
|
||||
and self._position > 1))
|
||||
if self.attrs.get('add_remove'):
|
||||
self.wid_text.set_sensitive(not self._readonly)
|
||||
self.but_add.set_sensitive(bool(
|
||||
not self._readonly
|
||||
and not size_limit
|
||||
@@ -299,6 +301,7 @@ class One2Many(Widget):
|
||||
and self._position
|
||||
and access['write']
|
||||
and access['read']))
|
||||
self.wid_text.set_sensitive(self.but_add.get_sensitive())
|
||||
|
||||
# New button must be added to focus chain to allow keyboard only
|
||||
# creation when there is no existing record on form view.
|
||||
|
||||
@@ -581,7 +581,8 @@ class M2O(GenericText):
|
||||
relation = field.attrs['relation']
|
||||
|
||||
access = common.MODELACCESS[relation]
|
||||
if create and not access['create']:
|
||||
if (create
|
||||
and not (self.attrs.get('create', True) and access['create'])):
|
||||
return
|
||||
elif not access['read']:
|
||||
return
|
||||
@@ -631,7 +632,10 @@ class M2O(GenericText):
|
||||
def set_completion(self, entry, path):
|
||||
if entry.get_completion():
|
||||
entry.set_completion(None)
|
||||
completion = get_completion()
|
||||
access = common.MODELACCESS[self.attrs['relation']]
|
||||
completion = get_completion(
|
||||
search=access['read'],
|
||||
create=self.attrs.get('create', True) and access['create'])
|
||||
completion.connect('match-selected', self._completion_match_selected,
|
||||
path)
|
||||
completion.connect('action-activated',
|
||||
|
||||
Reference in new issue
Block a user