Skip to content

Commit ee19e7f

Browse files
shepilov-vladislavbaimont
authored andcommitted
[12.0] web_notify: improve popup UI (#1231)
* [ADD]: all available bootstrap notifications (success/danger/warning/info/default) * [IMP] use black color for text for default notification. * [FIX] reverted require string for `bus.Longpolling` and rename `on_message_received` to `on_message` to prevent collisions.
1 parent 65596d0 commit ee19e7f

17 files changed

+404
-115
lines changed

web_notify/README.rst

+29-7
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@ Web Notify
2727

2828
Send instant notification messages to the user in live.
2929

30-
This technical module allows you to send instant notification messages from the server to the user in live.
30+
This technical module allows you to send instant notification messages from the server to the user in live.
3131
Two kinds of notification are supported.
3232

33-
* Warning: Displayed in a red flying popup div
34-
* Information: Displayed in a light yellow flying popup div
33+
* Success: Displayed in a `success` theme color flying popup div
34+
* Danger: Displayed in a `danger` theme color flying popup div
35+
* Warning: Displayed in a `warning` theme color flying popup div
36+
* Information: Displayed in a `info` theme color flying popup div
37+
* Default: Displayed in a `default` theme color flying popup div
3538

3639
**Table of contents**
3740

@@ -50,14 +53,32 @@ Usage
5053
To send a notification to the user you just need to call one of the new methods defined on res.users:
5154

5255
.. code-block:: python
53-
56+
57+
self.env.user.notify_success(message='My success message')
58+
59+
or
60+
61+
.. code-block:: python
62+
63+
self.env.user.notify_danger(message='My danger message')
64+
65+
or
66+
67+
.. code-block:: python
68+
69+
self.env.user.notify_warning(message='My warning message')
70+
71+
or
72+
73+
.. code-block:: python
74+
5475
self.env.user.notify_info(message='My information message')
5576
56-
or
77+
or
5778

5879
.. code-block:: python
59-
60-
self.env.user.notify_warning(message='My marning message')
80+
81+
self.env.user.notify_default(message='My default message')
6182
6283
.. figure:: https://raw.githubusercontent.com/OCA/web/12.0/web_notify/static/description/notifications_screenshot.png
6384
:scale: 80 %
@@ -95,6 +116,7 @@ Contributors
95116
* Laurent Mignon <[email protected]>
96117
* Serpent Consulting Services Pvt. Ltd.<[email protected]>
97118
* Aitor Bouzas <[email protected]>
119+
* Shepilov Vladislav <[email protected]>
98120

99121
Maintainers
100122
~~~~~~~~~~~

web_notify/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# pylint: disable=missing-docstring
12
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
23

34
from . import models

web_notify/__manifest__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# pylint: disable=missing-docstring
12
# Copyright 2016 ACSONE SA/NV
23
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
34

@@ -6,7 +7,6 @@
67
'summary': """
78
Send notification messages to user""",
89
'version': '12.0.1.0.0',
9-
'description': 'Web Notify',
1010
'license': 'AGPL-3',
1111
'author': 'ACSONE SA/NV,'
1212
'AdaptiveCity,'

web_notify/i18n/web_notify.pot

+51-3
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,80 @@ msgstr ""
1414
"Plural-Forms: \n"
1515

1616
#. module: web_notify
17-
#: code:addons/web_notify/models/res_users.py:23
17+
#: code:addons/web_notify/models/res_users.py:44
18+
#, python-format
19+
msgid "Danger"
20+
msgstr ""
21+
22+
#. module: web_notify
23+
#: code:addons/web_notify/models/res_users.py:60
24+
#, python-format
25+
msgid "Default"
26+
msgstr ""
27+
28+
#. module: web_notify
29+
#: code:addons/web_notify/models/res_users.py:54
1830
#, python-format
1931
msgid "Information"
2032
msgstr ""
2133

34+
#. module: web_notify
35+
#: model:ir.model.fields,field_description:web_notify.field_res_users__notify_danger_channel_name
36+
msgid "Notify Danger Channel Name"
37+
msgstr ""
38+
39+
#. module: web_notify
40+
#: model:ir.model.fields,field_description:web_notify.field_res_users__notify_default_channel_name
41+
msgid "Notify Default Channel Name"
42+
msgstr ""
43+
2244
#. module: web_notify
2345
#: model:ir.model.fields,field_description:web_notify.field_res_users__notify_info_channel_name
2446
msgid "Notify Info Channel Name"
2547
msgstr ""
2648

49+
#. module: web_notify
50+
#: model:ir.model.fields,field_description:web_notify.field_res_users__notify_success_channel_name
51+
msgid "Notify Success Channel Name"
52+
msgstr ""
53+
2754
#. module: web_notify
2855
#: model:ir.model.fields,field_description:web_notify.field_res_users__notify_warning_channel_name
2956
msgid "Notify Warning Channel Name"
3057
msgstr ""
3158

3259
#. module: web_notify
33-
#: code:addons/web_notify/models/res_users.py:37
60+
#: code:addons/web_notify/models/res_users.py:75
3461
#, python-format
3562
msgid "Sending a notification to another user is forbidden."
3663
msgstr ""
3764

65+
#. module: web_notify
66+
#: code:addons/web_notify/models/res_users.py:38
67+
#, python-format
68+
msgid "Success"
69+
msgstr ""
70+
71+
#. module: web_notify
72+
#: model_terms:ir.ui.view,arch_db:web_notify.view_users_form_simple_modif_inherit
73+
msgid "Test danger notification"
74+
msgstr ""
75+
76+
#. module: web_notify
77+
#: model_terms:ir.ui.view,arch_db:web_notify.view_users_form_simple_modif_inherit
78+
msgid "Test default notification"
79+
msgstr ""
80+
3881
#. module: web_notify
3982
#: model_terms:ir.ui.view,arch_db:web_notify.view_users_form_simple_modif_inherit
4083
msgid "Test info notification"
4184
msgstr ""
4285

86+
#. module: web_notify
87+
#: model_terms:ir.ui.view,arch_db:web_notify.view_users_form_simple_modif_inherit
88+
msgid "Test success notification"
89+
msgstr ""
90+
4391
#. module: web_notify
4492
#: model_terms:ir.ui.view,arch_db:web_notify.view_users_form_simple_modif_inherit
4593
msgid "Test warning notification"
@@ -56,7 +104,7 @@ msgid "Users"
56104
msgstr ""
57105

58106
#. module: web_notify
59-
#: code:addons/web_notify/models/res_users.py:29
107+
#: code:addons/web_notify/models/res_users.py:50
60108
#, python-format
61109
msgid "Warning"
62110
msgstr ""

web_notify/models/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# pylint: disable=missing-docstring
12
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
23

34
from . import res_users

web_notify/models/res_users.py

+70-29
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,87 @@
1+
# pylint: disable=missing-docstring
12
# Copyright 2016 ACSONE SA/NV
23
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
34

4-
from odoo import api, exceptions, fields, models, _
5+
from odoo import _, api, exceptions, fields, models
6+
7+
DEFAULT_MESSAGE = "Default message"
8+
9+
SUCCESS = "success"
10+
DANGER = "danger"
11+
WARNING = "warning"
12+
INFO = "info"
13+
DEFAULT = "default"
514

615

716
class ResUsers(models.Model):
8-
_inherit = 'res.users'
17+
_inherit = "res.users"
918

10-
@api.depends('create_date')
19+
@api.depends("create_date")
1120
def _compute_channel_names(self):
1221
for record in self:
1322
res_id = record.id
14-
record.notify_info_channel_name = 'notify_info_%s' % res_id
15-
record.notify_warning_channel_name = 'notify_warning_%s' % res_id
23+
record.notify_success_channel_name = "notify_success_%s" % res_id
24+
record.notify_danger_channel_name = "notify_danger_%s" % res_id
25+
record.notify_warning_channel_name = "notify_warning_%s" % res_id
26+
record.notify_info_channel_name = "notify_info_%s" % res_id
27+
record.notify_default_channel_name = "notify_default_%s" % res_id
28+
29+
notify_success_channel_name = fields.Char(compute="_compute_channel_names")
30+
notify_danger_channel_name = fields.Char(compute="_compute_channel_names")
31+
notify_warning_channel_name = fields.Char(compute="_compute_channel_names")
32+
notify_info_channel_name = fields.Char(compute="_compute_channel_names")
33+
notify_default_channel_name = fields.Char(compute="_compute_channel_names")
34+
35+
def notify_success(
36+
self, message="Default message", title=None, sticky=False
37+
):
38+
title = title or _("Success")
39+
self._notify_channel(SUCCESS, message, title, sticky)
1640

17-
notify_info_channel_name = fields.Char(
18-
compute='_compute_channel_names')
19-
notify_warning_channel_name = fields.Char(
20-
compute='_compute_channel_names')
41+
def notify_danger(
42+
self, message="Default message", title=None, sticky=False
43+
):
44+
title = title or _("Danger")
45+
self._notify_channel(DANGER, message, title, sticky)
46+
47+
def notify_warning(
48+
self, message="Default message", title=None, sticky=False
49+
):
50+
title = title or _("Warning")
51+
self._notify_channel(WARNING, message, title, sticky)
2152

2253
def notify_info(self, message="Default message", title=None, sticky=False):
23-
title = title or _('Information')
24-
self._notify_channel(
25-
'notify_info_channel_name', message, title, sticky)
26-
27-
def notify_warning(self, message="Default message",
28-
title=None, sticky=False):
29-
title = title or _('Warning')
30-
self._notify_channel(
31-
'notify_warning_channel_name', message, title, sticky)
32-
33-
def _notify_channel(self, channel_name_field, message, title, sticky):
34-
if (not self.env.user._is_admin()
35-
and any(user.id != self.env.uid for user in self)):
54+
title = title or _("Information")
55+
self._notify_channel(INFO, message, title, sticky)
56+
57+
def notify_default(
58+
self, message="Default message", title=None, sticky=False
59+
):
60+
title = title or _("Default")
61+
self._notify_channel(DEFAULT, message, title, sticky)
62+
63+
def _notify_channel(
64+
self,
65+
type_message=DEFAULT,
66+
message=DEFAULT_MESSAGE,
67+
title=None,
68+
sticky=False,
69+
):
70+
# pylint: disable=protected-access
71+
if not self.env.user._is_admin() and any(
72+
user.id != self.env.uid for user in self
73+
):
3674
raise exceptions.UserError(
37-
_('Sending a notification to another user is forbidden.')
75+
_("Sending a notification to another user is forbidden.")
3876
)
77+
channel_name_field = "notify_{}_channel_name".format(type_message)
3978
bus_message = {
40-
'message': message,
41-
'title': title,
42-
'sticky': sticky
79+
"type": type_message,
80+
"message": message,
81+
"title": title,
82+
"sticky": sticky,
4383
}
44-
notifications = [(record[channel_name_field], bus_message)
45-
for record in self]
46-
self.env['bus.bus'].sendmany(notifications)
84+
notifications = [
85+
(record[channel_name_field], bus_message) for record in self
86+
]
87+
self.env["bus.bus"].sendmany(notifications)

web_notify/readme/CONTRIBUTORS.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
* Laurent Mignon <[email protected]>
22
* Serpent Consulting Services Pvt. Ltd.<[email protected]>
3-
* Aitor Bouzas <[email protected]>
3+
* Aitor Bouzas <[email protected]>
4+
* Shepilov Vladislav <[email protected]>

web_notify/readme/DESCRIPTION.rst

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
Send instant notification messages to the user in live.
22

3-
This technical module allows you to send instant notification messages from the server to the user in live.
3+
This technical module allows you to send instant notification messages from the server to the user in live.
44
Two kinds of notification are supported.
55

6-
* Warning: Displayed in a red flying popup div
7-
* Information: Displayed in a light yellow flying popup div
6+
* Success: Displayed in a `success` theme color flying popup div
7+
* Danger: Displayed in a `danger` theme color flying popup div
8+
* Warning: Displayed in a `warning` theme color flying popup div
9+
* Information: Displayed in a `info` theme color flying popup div
10+
* Default: Displayed in a `default` theme color flying popup div

web_notify/readme/INSTALL.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
This module is based on the Instant Messaging Bus. To work properly, the server must be launched in gevent mode.
1+
This module is based on the Instant Messaging Bus. To work properly, the server must be launched in gevent mode.

web_notify/readme/USAGE.rst

+22-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,32 @@
22
To send a notification to the user you just need to call one of the new methods defined on res.users:
33

44
.. code-block:: python
5-
5+
6+
self.env.user.notify_success(message='My success message')
7+
8+
or
9+
10+
.. code-block:: python
11+
12+
self.env.user.notify_danger(message='My danger message')
13+
14+
or
15+
16+
.. code-block:: python
17+
18+
self.env.user.notify_warning(message='My warning message')
19+
20+
or
21+
22+
.. code-block:: python
23+
624
self.env.user.notify_info(message='My information message')
725
8-
or
26+
or
927

1028
.. code-block:: python
11-
12-
self.env.user.notify_warning(message='My marning message')
29+
30+
self.env.user.notify_default(message='My default message')
1331
1432
.. figure:: static/description/notifications_screenshot.png
1533
:scale: 80 %

0 commit comments

Comments
 (0)