From 333ce2bd9b55ca6378bfd90fd0114267516e382b Mon Sep 17 00:00:00 2001 From: Jorran de Wit <jorrandewit@outlook.com> Date: Tue, 12 Sep 2017 22:06:25 +0200 Subject: [PATCH] Easy sending of notifications using signals --- notifications/__init__.py | 1 + notifications/apps.py | 5 +++++ notifications/signals.py | 13 +++++++++++++ 3 files changed, 19 insertions(+) create mode 100644 notifications/signals.py diff --git a/notifications/__init__.py b/notifications/__init__.py index e69de29bb..41f694b45 100644 --- a/notifications/__init__.py +++ b/notifications/__init__.py @@ -0,0 +1 @@ +default_app_config = 'notifications.apps.Config' diff --git a/notifications/apps.py b/notifications/apps.py index 9c260e0b1..5a0aef11b 100644 --- a/notifications/apps.py +++ b/notifications/apps.py @@ -3,3 +3,8 @@ from django.apps import AppConfig class NotificationsConfig(AppConfig): name = 'notifications' + + def ready(self): + super().ready() + import notifications.signals + notifications.notify = notifications.signals.notify diff --git a/notifications/signals.py b/notifications/signals.py new file mode 100644 index 000000000..3de9da7d6 --- /dev/null +++ b/notifications/signals.py @@ -0,0 +1,13 @@ +from django.dispatch import Signal + +notify = Signal(providing_args=[ + 'recipient', 'actor', 'verb', 'action_object', 'target', 'description', + 'timestamp', 'level' +]) + + +# Basic working method to send a notification to a user using signals: +# --- +# from notifications.signals import notify +# notify.send(user, recipient=user, verb='you reached level 10') +# --- -- GitLab