-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathapps.py
48 lines (37 loc) · 1.54 KB
/
apps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from django.db.models.signals import post_save
from swapper import load_model
from openwisp_notifications.apps import OpenwispNotificationsConfig
from openwisp_notifications.types import register_notification_type
from .signals import test_app_name_changed
class SampleNotificationsConfig(OpenwispNotificationsConfig):
name = 'openwisp2.sample_notifications'
label = 'sample_notifications'
verbose_name = 'Notifications (custom)'
def ready(self):
super().ready()
self.register_notification_types()
self.connect_receivers()
def register_notification_types(self):
register_notification_type(
'object_created',
{
'verbose_name': 'Object created',
'verb': 'created',
'level': 'info',
'message': '{notification.target} object {notification.verb}.',
'email_subject': '[{site.name}] INFO: {notification.target} created',
},
)
def connect_receivers(self):
from openwisp_notifications.handlers import register_notification_cache_update
Organization = load_model('openwisp_users', 'Organization')
from .models import TestApp
register_notification_cache_update(
Organization, post_save, dispatch_uid='organization_post_save_invalidation'
)
register_notification_cache_update(
TestApp,
test_app_name_changed,
dispatch_uid='test_app_name_changed_invalidation',
)
del OpenwispNotificationsConfig