Simple user notification management for the Django web framework
Project description
Usage
1. create notification events
from notifications.handlers import send_message
send_message('Mahmoud Liked your post', user, 'post_like')
Explain
# function interface
send_message(message:str, user:User, type:str)
# logic behind it
message: the text message to be sent to the user
user: an instance of User model (the one who will recieve the notification)
type: is a notification tag (you should create difrrent types in your system for different events)
2.fetch notifications using REST APIs
notifications/all/
:GET : get all the notifications
notifications/mark/
:PUT : mark all notifications as read
notifications/unread/
:GET: get all unread notifications
3.how the client side recieve the message from the server via websocket
configration
Note: make sure that django chanels is up and runnnig and also you django serves under ASGI check this url to configure django channels in your project
in settings.py
INSTALLED_APPS = [
...
'channels', # django channels needs to be installed
'notifications', # our package
...
]
SIMPLE_NOTIFICATION_SETTINGS = {
'receive_handler_path': 'custom_module.custom_py_file.custom_receive_handler',
}
in urls.py
path('api/v1/notifications/', include('notifications.urls')),
in asgi.py
from notifications import routing
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'demo_project.settings')
application = ProtocolTypeRouter({
'http': get_asgi_application(),
'websocket': AuthMiddlewareStack(
URLRouter(
routing.websocket_urlpatterns
)
),
})
run make migrate:
python manage.py migrate
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-simple-notification-1.0.4.tar.gz
.
File metadata
- Download URL: django-simple-notification-1.0.4.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b9e5317fe755eea51765457e3ef93d603ded1929ea3ac932ddc3b980f041e2f |
|
MD5 | c38e4171380c65809f94c0e564c56fe9 |
|
BLAKE2b-256 | cfa015330c1701f16f7df9bb2fdba933e161019ee1dd60eafb073cbac6088e0f |