Git Product home page Git Product logo

django_simple_notification's Introduction

install

pip install django-simple-notification

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 different 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

img_1.png


notifications/unread/:GET: get all unread notifications

img_2.png

3.how the client side recieve the message from the server via websocket

img.png

configration

Note: make sure that django channels 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
    ...   
]
# Note: this step is optional
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
        )
    ),
})

# or if you have other routing files you can do this
application = ProtocolTypeRouter({
    'http': get_asgi_application(),
    'websocket': AuthMiddlewareStack(
        URLRouter([
            *routing.websocket_urlpatterns,
            *other_routing1.websocket_urlpatterns,
            *other_routing2.websocket_urlpatterns,
        ])
    ),
})

run make migrate:

python manage.py migrate

django_simple_notification's People

Contributors

mahmoudnasser01 avatar abdelrahman725 avatar muzmmil207 avatar mzdehbashi-github avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.