django-easy-notify


Namedjango-easy-notify JSON
Version 1.1 PyPI version JSON
download
home_pagehttps://github.com/Hashtrust-technology-private-limited/django-easy-notify
SummaryA Django Library to send notifications in easy way
upload_time2023-07-27 12:27:40
maintainer
docs_urlNone
authorHashtrust Technologies Private Limited
requires_python>=3.9
licenseMIT License
keywords
VCS
bugtrack_url
requirements channels channels-redis daphne Django django-channels docutils factory-boy Faker flake8 flake8-bugbear Pillow pytest coverage pytest-django python-dateutil redis requests six urllib3
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # django-easy-notify

django-easy-notify is Django App to create/send notification by calling just hit of single function.

Quick Start
-----------
1. Add 'notifications' to your INSTALLED_APPS setting like this::
    ```
    INSTALLED_APPS = [
        ...
        'daphne',
        'channels',
        'notifications',
    ]
    ```
2. Run ``python manage.py migrate`` to create the django-mails models.
3. Add Templates path to your TEMPLATES in setting.py
4. import method to send email ``from notifications.utils import send_notification``
5. Use method ``from notifications.utils import get_notifications`` to receive notifications based on status/all notifications.


Description
-----------
# To Send or Create Notification

```
send_notification(
    title : str,
    receivers : list[User],
    sender : User,
    notification_type : str,
    message : str = None,
    category : Category = None,
    real_time_notification : bool = False
)
```
* This function will create in-app notification with required details.

* Parameters:
1. title : string
2. receivers : List of User model instance
3. sender : User model instance
4. notification_type :
    a. success
    b. error
    c. warning
    d. info
5. message : string
6. category : Category Model instance
7. notification_status :
    a. read
    b. unread
    c. deleted
8. real_time_notification : bool (Set True if you want to implement Real-Time Notifications)

# To fetch notifications

```
get_notifications(user, notification_status = None):
```
* Parameters:
1. user : Instance of User Model (Receiver)
2. notification_status :
    a. read
    b. unread
    c. deleted
    Note : Set None to receive all notifications.

# Mark as Read
```
mark_as_read(user)
```
* Parameters:
1. user : Instance of User Model (Receiver)

# Mark as Unread
```
mark_as_unread(user)
```
* Parameters:
1. user : Instance of User Model (Receiver)


Django Channels Setting
-----------------------

```
ASGI_APPLICATION = "<your_project_name>".asgi.application"
CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "channels_redis.core.RedisChannelLayer",
        "CONFIG": {
            "hosts": [("localhost", 6379)],
        },
    },
}
```

* Update ASGI file

```
import os

from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from django.core.asgi import get_asgi_application

import notifications.routing

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "<your_project_name>.settings")

application = ProtocolTypeRouter(
    {
        "http": get_asgi_application(),
        "websocket": AuthMiddlewareStack(
            URLRouter(notifications.routing.websocket_urlpatterns)
        ),
    }
)
```

* Script to work with websockets on Frontend side.
```
<script>
    var loc = window.location
        var wsStart = "ws://"
        if (loc.protocol == "https:"){
            wsStart = "wss://"
        }
        var webSocketEndpoint =  wsStart + loc.host + '/ws/notifications/' + "{{user.id}}/" // ws : wss   // Websocket URL, Same on as mentioned in the routing.py


        var socket = new WebSocket(webSocketEndpoint) // Creating a new Web Socket Connection

        // Socket On receive message Functionality
        socket.onmessage = function(e){
            console.log('message', e)
            console.log(JSON.parse(e.data))
        }

        // Socket Connet Functionality
        socket.onopen = function(e){
            console.log('open', e)
            socket.send(JSON.stringify({
                "command":"fetch_all_notifications" // send command to fetch all unread notifications
            }))
        }

        // Socket Error Functionality
        socket.onerror = function(e){
            console.log('error', e)
        }

        // Socket close Functionality
        socket.onclose = function(e){
            console.log('closed', e)
        }
</script>
```
# Setup guideline

- build: Create the build and runtime images
```
    docker-compose build
```

- up: Start up the project
```
    docker-compose up
```
- To see services and their ports
```
    docker ps
```
- shell: Shell into the running Django container
```
    docker exec -it CONTAINER ID /bin/bash
```
- migrate: Changes you have made to your models
```
   python manage.py makemigrations
   python manage.py migrate
   python manage.py createsuperuser
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Hashtrust-technology-private-limited/django-easy-notify",
    "name": "django-easy-notify",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "",
    "author": "Hashtrust Technologies Private Limited",
    "author_email": "support@hashtrust.in",
    "download_url": "https://files.pythonhosted.org/packages/a1/bb/b0491b6a6e04537a2fa346ddaf1681de0e83dd412c441f84916dfc41f7de/django-easy-notify-1.1.tar.gz",
    "platform": null,
    "description": "# django-easy-notify\n\ndjango-easy-notify is Django App to create/send notification by calling just hit of single function.\n\nQuick Start\n-----------\n1. Add 'notifications' to your INSTALLED_APPS setting like this::\n    ```\n    INSTALLED_APPS = [\n        ...\n        'daphne',\n        'channels',\n        'notifications',\n    ]\n    ```\n2. Run ``python manage.py migrate`` to create the django-mails models.\n3. Add Templates path to your TEMPLATES in setting.py\n4. import method to send email ``from notifications.utils import send_notification``\n5. Use method ``from notifications.utils import get_notifications`` to receive notifications based on status/all notifications.\n\n\nDescription\n-----------\n# To Send or Create Notification\n\n```\nsend_notification(\n    title : str,\n    receivers : list[User],\n    sender : User,\n    notification_type : str,\n    message : str = None,\n    category : Category = None,\n    real_time_notification : bool = False\n)\n```\n* This function will create in-app notification with required details.\n\n* Parameters:\n1. title : string\n2. receivers : List of User model instance\n3. sender : User model instance\n4. notification_type :\n    a. success\n    b. error\n    c. warning\n    d. info\n5. message : string\n6. category : Category Model instance\n7. notification_status :\n    a. read\n    b. unread\n    c. deleted\n8. real_time_notification : bool (Set True if you want to implement Real-Time Notifications)\n\n# To fetch notifications\n\n```\nget_notifications(user, notification_status = None):\n```\n* Parameters:\n1. user : Instance of User Model (Receiver)\n2. notification_status :\n    a. read\n    b. unread\n    c. deleted\n    Note : Set None to receive all notifications.\n\n# Mark as Read\n```\nmark_as_read(user)\n```\n* Parameters:\n1. user : Instance of User Model (Receiver)\n\n# Mark as Unread\n```\nmark_as_unread(user)\n```\n* Parameters:\n1. user : Instance of User Model (Receiver)\n\n\nDjango Channels Setting\n-----------------------\n\n```\nASGI_APPLICATION = \"<your_project_name>\".asgi.application\"\nCHANNEL_LAYERS = {\n    \"default\": {\n        \"BACKEND\": \"channels_redis.core.RedisChannelLayer\",\n        \"CONFIG\": {\n            \"hosts\": [(\"localhost\", 6379)],\n        },\n    },\n}\n```\n\n* Update ASGI file\n\n```\nimport os\n\nfrom channels.auth import AuthMiddlewareStack\nfrom channels.routing import ProtocolTypeRouter, URLRouter\nfrom django.core.asgi import get_asgi_application\n\nimport notifications.routing\n\nos.environ.setdefault(\"DJANGO_SETTINGS_MODULE\", \"<your_project_name>.settings\")\n\napplication = ProtocolTypeRouter(\n    {\n        \"http\": get_asgi_application(),\n        \"websocket\": AuthMiddlewareStack(\n            URLRouter(notifications.routing.websocket_urlpatterns)\n        ),\n    }\n)\n```\n\n* Script to work with websockets on Frontend side.\n```\n<script>\n    var loc = window.location\n        var wsStart = \"ws://\"\n        if (loc.protocol == \"https:\"){\n            wsStart = \"wss://\"\n        }\n        var webSocketEndpoint =  wsStart + loc.host + '/ws/notifications/' + \"{{user.id}}/\" // ws : wss   // Websocket URL, Same on as mentioned in the routing.py\n\n\n        var socket = new WebSocket(webSocketEndpoint) // Creating a new Web Socket Connection\n\n        // Socket On receive message Functionality\n        socket.onmessage = function(e){\n            console.log('message', e)\n            console.log(JSON.parse(e.data))\n        }\n\n        // Socket Connet Functionality\n        socket.onopen = function(e){\n            console.log('open', e)\n            socket.send(JSON.stringify({\n                \"command\":\"fetch_all_notifications\" // send command to fetch all unread notifications\n            }))\n        }\n\n        // Socket Error Functionality\n        socket.onerror = function(e){\n            console.log('error', e)\n        }\n\n        // Socket close Functionality\n        socket.onclose = function(e){\n            console.log('closed', e)\n        }\n</script>\n```\n# Setup guideline\n\n- build: Create the build and runtime images\n```\n    docker-compose build\n```\n\n- up: Start up the project\n```\n    docker-compose up\n```\n- To see services and their ports\n```\n    docker ps\n```\n- shell: Shell into the running Django container\n```\n    docker exec -it CONTAINER ID /bin/bash\n```\n- migrate: Changes you have made to your models\n```\n   python manage.py makemigrations\n   python manage.py migrate\n   python manage.py createsuperuser\n```\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "A Django Library to send notifications in easy way",
    "version": "1.1",
    "project_urls": {
        "Homepage": "https://github.com/Hashtrust-technology-private-limited/django-easy-notify"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a1bbb0491b6a6e04537a2fa346ddaf1681de0e83dd412c441f84916dfc41f7de",
                "md5": "0ecab0a37a81c7e38101f9a73fb9f7cb",
                "sha256": "dc8c04fb25f9a98a3a185c42e7ab99e223be1d799e966c1ed55dd17c3fdba2de"
            },
            "downloads": -1,
            "filename": "django-easy-notify-1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "0ecab0a37a81c7e38101f9a73fb9f7cb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 9863,
            "upload_time": "2023-07-27T12:27:40",
            "upload_time_iso_8601": "2023-07-27T12:27:40.631909Z",
            "url": "https://files.pythonhosted.org/packages/a1/bb/b0491b6a6e04537a2fa346ddaf1681de0e83dd412c441f84916dfc41f7de/django-easy-notify-1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-27 12:27:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Hashtrust-technology-private-limited",
    "github_project": "django-easy-notify",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "channels",
            "specs": [
                [
                    "==",
                    "3.0.4"
                ]
            ]
        },
        {
            "name": "channels-redis",
            "specs": [
                [
                    "==",
                    "4.1.0"
                ]
            ]
        },
        {
            "name": "daphne",
            "specs": [
                [
                    "==",
                    "3.0.2"
                ]
            ]
        },
        {
            "name": "Django",
            "specs": [
                [
                    "==",
                    "4.1.3"
                ]
            ]
        },
        {
            "name": "django-channels",
            "specs": [
                [
                    "==",
                    "0.7.0"
                ]
            ]
        },
        {
            "name": "docutils",
            "specs": [
                [
                    "==",
                    "0.19"
                ]
            ]
        },
        {
            "name": "factory-boy",
            "specs": [
                [
                    "==",
                    "3.2.1"
                ]
            ]
        },
        {
            "name": "Faker",
            "specs": [
                [
                    "==",
                    "18.9.0"
                ]
            ]
        },
        {
            "name": "flake8",
            "specs": [
                [
                    "==",
                    "6.0.0"
                ]
            ]
        },
        {
            "name": "flake8-bugbear",
            "specs": [
                [
                    "==",
                    "23.5.9"
                ]
            ]
        },
        {
            "name": "Pillow",
            "specs": [
                [
                    "==",
                    "9.5.0"
                ]
            ]
        },
        {
            "name": "pytest",
            "specs": [
                [
                    "==",
                    "7.3.1"
                ]
            ]
        },
        {
            "name": "coverage",
            "specs": [
                [
                    "==",
                    "7.2.7"
                ]
            ]
        },
        {
            "name": "pytest-django",
            "specs": [
                [
                    "==",
                    "4.5.2"
                ]
            ]
        },
        {
            "name": "python-dateutil",
            "specs": [
                [
                    "==",
                    "2.8.2"
                ]
            ]
        },
        {
            "name": "redis",
            "specs": [
                [
                    "==",
                    "4.5.4"
                ]
            ]
        },
        {
            "name": "requests",
            "specs": [
                [
                    "==",
                    "2.29.0"
                ]
            ]
        },
        {
            "name": "six",
            "specs": [
                [
                    "==",
                    "1.16.0"
                ]
            ]
        },
        {
            "name": "urllib3",
            "specs": [
                [
                    "==",
                    "1.26.15"
                ]
            ]
        }
    ],
    "lcname": "django-easy-notify"
}
        
Elapsed time: 0.10397s