# install
```shell
pip install django-simple-notification
```
# Usage
## 1. create notification events
```python
from notifications.handlers import send_message
send_message('Mahmoud Liked your post', user, 'post_like')
```
Explain
```python
# 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 or type (you should create difrrent types in your system for different events)
```
## 2.fetch notifications using REST APIs
``notifications/all/``:GET : get all the notifications
<br/><br/>
``notifications/mark/``:PUT : mark all notifications as read
![img_1.png](https://github.com/MahmoudNasser01/django_simple_notification/blob/master/read_me_media/img_1.png?raw=true)
<br/><br/><br/>
``notifications/unread/``:GET: get all unread notifications
![img_2.png](https://github.com/MahmoudNasser01/django_simple_notification/blob/master/read_me_media/img_2.png?raw=true)
## 3.how the client side recieve the message from the server via websocket
![img.png](https://github.com/MahmoudNasser01/django_simple_notification/blob/master/read_me_media/img.png?raw=true)
# configration
Note: make sure that django channels is up and running and also you django serves under ASGI
check this [url](https://channels.readthedocs.io/en/stable/installation.html) to configure django channels in your project
in ``settings.py``
``` python
INSTALLED_APPS = [
...
'channels', # django channels needs to be installed
'notifications', # our package
...
]
```
```python
SIMPLE_NOTIFICATION_SETTINGS = {
'receive_handler_path': 'custom_module.custom_py_file.custom_receive_handler',
}
```
in ``urls.py``
```python
path('api/v1/notifications/', include('notifications.urls')),
```
in ``asgi.py``
```python
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:
```shell
python manage.py migrate
```
Raw data
{
"_id": null,
"home_page": "https://github.com/MahmoudNasser01/django_simple_notification",
"name": "django-simple-notification",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "django notification simple custom",
"author": "Mahmoud Nasser",
"author_email": "mahmoud.nasser.abdulhamed@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/45/f3/559603e264bca2338c8a0a375a2fa8c9da2b81cbeb88d4aa3e9c23509cbc/django-simple-notification-1.0.5.tar.gz",
"platform": null,
"description": "# install\n\n```shell\npip install django-simple-notification\n```\n\n# Usage\n\n## 1. create notification events\n\n```python\n\nfrom notifications.handlers import send_message\n\nsend_message('Mahmoud Liked your post', user, 'post_like')\n```\nExplain\n```python\n# function interface\nsend_message(message:str, user:User, type:str)\n\n# logic behind it\nmessage: the text message to be sent to the user\nuser: an instance of User model (the one who will recieve the notification)\ntype: is a notification tag or type (you should create difrrent types in your system for different events)\n```\n## 2.fetch notifications using REST APIs\n\n``notifications/all/``:GET : get all the notifications\n\n<br/><br/>\n``notifications/mark/``:PUT : mark all notifications as read\n\n![img_1.png](https://github.com/MahmoudNasser01/django_simple_notification/blob/master/read_me_media/img_1.png?raw=true)\n<br/><br/><br/>\n\n``notifications/unread/``:GET: get all unread notifications\n\n![img_2.png](https://github.com/MahmoudNasser01/django_simple_notification/blob/master/read_me_media/img_2.png?raw=true)\n\n## 3.how the client side recieve the message from the server via websocket\n![img.png](https://github.com/MahmoudNasser01/django_simple_notification/blob/master/read_me_media/img.png?raw=true)\n\n\n# configration\n\nNote: make sure that django channels is up and running and also you django serves under ASGI\ncheck this [url](https://channels.readthedocs.io/en/stable/installation.html) to configure django channels in your project\n\nin ``settings.py``\n``` python\nINSTALLED_APPS = [\n ...\n 'channels', # django channels needs to be installed\n 'notifications', # our package\n ... \n]\n```\n\n\n```python\n\nSIMPLE_NOTIFICATION_SETTINGS = {\n 'receive_handler_path': 'custom_module.custom_py_file.custom_receive_handler',\n}\n```\n\n\nin ``urls.py``\n\n```python\npath('api/v1/notifications/', include('notifications.urls')),\n```\n\nin ``asgi.py``\n\n```python\nfrom notifications import routing\n\nos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'demo_project.settings')\n\napplication = ProtocolTypeRouter({\n 'http': get_asgi_application(),\n 'websocket': AuthMiddlewareStack(\n URLRouter(\n routing.websocket_urlpatterns\n )\n ),\n})\n\n```\nrun make migrate:\n\n```shell\npython manage.py migrate\n```\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Simple user notification management for the Django web framework",
"version": "1.0.5",
"project_urls": {
"Homepage": "https://github.com/MahmoudNasser01/django_simple_notification"
},
"split_keywords": [
"django",
"notification",
"simple",
"custom"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "45f3559603e264bca2338c8a0a375a2fa8c9da2b81cbeb88d4aa3e9c23509cbc",
"md5": "92add6f2f9bc5db9690eda372501233d",
"sha256": "54a57081d46f9726d78d248799d001a2a3cac7874b855a671b41c0706b253bed"
},
"downloads": -1,
"filename": "django-simple-notification-1.0.5.tar.gz",
"has_sig": false,
"md5_digest": "92add6f2f9bc5db9690eda372501233d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 6661,
"upload_time": "2023-06-22T15:27:45",
"upload_time_iso_8601": "2023-06-22T15:27:45.552794Z",
"url": "https://files.pythonhosted.org/packages/45/f3/559603e264bca2338c8a0a375a2fa8c9da2b81cbeb88d4aa3e9c23509cbc/django-simple-notification-1.0.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-06-22 15:27:45",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "MahmoudNasser01",
"github_project": "django_simple_notification",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "django-simple-notification"
}