Add notification message

issue11065
review367951004
This commit is contained in:
Cédric Krier
2022-04-11 23:41:21 +02:00
parent fcbe0df011
commit 4ecc0c4c71
5 changed files with 43 additions and 1 deletions
+1
View File
@@ -1,3 +1,4 @@
* Add notification message
* Add validate_fields to ModelStorage
* Drop support for PyPy and psycopg2cffi
* Use a set for field's depends
+9
View File
@@ -113,6 +113,15 @@ Instance methods:
Return the new values of all fields by calling ``on_change_with`` method of
each field.
.. method:: Model.on_change_notify(fieldnames)
Returns a list of type and message couple to display on the client side.
Available types are ``info``, ``warning`` and ``error``.
.. note::
To be called by the client, this method must be decorated
by :meth:`~trytond.model.fields.depends` with the fields needed.
.. method:: Model.pre_validate()
Validate the instance before being stored.
+10
View File
@@ -73,6 +73,7 @@ class Model(ModelSQL, ModelView):
cls.__rpc__.update({
'list_models': RPC(),
'list_history': RPC(),
'get_notification': RPC(),
'get_names': RPC(),
'global_search': RPC(),
})
@@ -145,6 +146,15 @@ class Model(ModelSQL, ModelView):
return [name for name, model in Pool().iterobject()
if getattr(model, '_history', False)]
@classmethod
def get_notification(cls):
"Return a dictionary of model to notify with the depending fields"
return {
name: list(model._on_change_notify_depends)
for name, model in Pool().iterobject()
if issubclass(model, ModelView)
and model._on_change_notify_depends}
@classmethod
def get_name_items(cls):
"Return a list of couple mapping models to names"
+22
View File
@@ -50,6 +50,7 @@ class ModelView(Model):
cls.__rpc__['view_toolbar_get'] = RPC(cache=dict(days=1))
cls.__rpc__['on_change'] = RPC(instantiate=0)
cls.__rpc__['on_change_with'] = RPC(instantiate=0)
cls.__rpc__['on_change_notify'] = RPC(instantiate=0)
cls._buttons = {}
fields_ = {}
@@ -165,6 +166,21 @@ class ModelView(Model):
methods['depend_methods'][meth_name] - meth_done)
meth_done.add(meth_name)
set_methods('on_change_notify')
cls._on_change_notify_depends = methods['depends']['on_change_notify']
meth_names = list(methods['depend_methods']['on_change_notify'])
meth_done = set()
while meth_names:
meth_name = meth_names.pop()
method = getattr(cls, meth_name)
assert callable(method) or isinstance(method, property), \
"%s.%s not callable or property" % (cls, meth_name)
set_methods(meth_name)
cls._on_change_notify_depends |= methods['depends'][meth_name]
meth_names += list(
methods['depend_methods'][meth_name] - meth_done)
meth_done.add(meth_name)
@classmethod
def fields_view_get(cls, view_id=None, view_type='form', level=None):
'''
@@ -744,6 +760,12 @@ class ModelView(Model):
changes[fieldname] = getattr(self, method_name)()
return changes
def on_change_notify(self):
"""Return a list of type and message couples.
Available types are info, warning and error.
"""
return []
@property
def _changed_values(self):
"""Return the values changed since the instantiation.
+1 -1
View File
@@ -427,7 +427,7 @@ class ModuleTestCase(unittest.TestCase):
for prefixes in [['default_'],
['on_change_', 'on_change_with_'],
['order_'], ['domain_'], ['autocomplete_']]:
if attr == 'on_change_with':
if attr in {'on_change_with', 'on_change_notify'}:
continue
# TODO those method should be renamed
if attr == 'default_get':