Skip to main content

Notification sytem for Django

Project description

Documentation Status https://badge.fury.io/py/django-notify-x.svg https://travis-ci.org/v1k45/django-notify-x.svg

Django NotifyX is a reusable app which adds notification system features to your Django app.

It was inspired from django-notifications , major differences include:
  • Multipe user notification at once.

  • A different approach for notification updates.

  • Less hassles when trying to format notifications differently according to their types.

  • AJAX support for everything.

  • And many more.

This is just a quick guide to get things to work ASAP. To dive into the details.. Read the docs

How to install

Downloading the package

Probably the best way to install is by using PIP:

$ pip install django-notify-x

If you want to stay on the bleeding edge of the app:

$ git clone https://github.com/v1k45/django-notify-x.git
$ cd django-notify-x
$ python setup.py install

Installing it on your project

After the you’ve installed django-notify-x in your python enviroment. You have to make an entry of the same in your project settings.py file:

INSTALLED_APPS = (
    ...
    'your.other.apps',
    ...
    'notify',
)

Then an entry on the urls.py file:

urlpatterns = (
    url(r'^notifications/', include('notify.urls', 'notifications')),
)

Then run migrations:

$ python manage.py migrate notify

Then collectstatic to make sure you’ve copied the JS file for AJAX functionality:

$ python manage.py collectstatic

You’ve successfully installed django-notify-x!

Sending notifications

Sending notifications to a single user:

from notify.signals import notify

# your example view
def follow_user(request, user):
    user = User.objects.get(username=user)
    ...
    dofollow
    ...

    notify.send(request.user, recipient=user, actor=request.user
                verb='followed you.', nf_type='followed_by_one_user')

    return YourResponse

Easy as pie, isn’t it?

Sending notifications to multiple users:

from notify.signals import notify

# your example view
def upload_video(request):
    ...
    uploadvideo...
    ...
    video = VideoUploader.getupload()
    followers = list(request.user.followers())

    notify.send(request.user, recipient_list=followers, actor=request.user
                verb='uploaded.', target=video, nf_type='video_upload_from_following')

    return YourResponse

Just change the recipient to recipient_list and send notifications to as many users you want!

Notification concatenation support

Notification Concatenation is what you see when you read notifications like Bob and 64 others liked your status. A developmental support is available for it, but it only supports Python3 for now.

If you use Python3, you can add this feature to your application. Please read instructions on nf_concat_support branch.

Notification Template tags

This app comes with two notification tags, one renders notifications for you and the other includes javascript variables and functions relating the notifyX.js file.

render_notifications

As its name reflects, it will render notifications for you. render_notifications will take at least one parameter and maximum two parameters.

You can use them to render notifications using a Notification QuerySet object, like this:

{% load notification_tags %}
{% render_notifications using request.user.notifications.active %}

By default, the above tag will render notifications on the notifications page and not on the notification box. So it will use a template corresponing to it’s nf_type with a .htm suffix nothing more.

To render notificatons on a notifications box:

{% load notification_tags %}
{% render_notifications using request.user.notifications.active for box %}

This tag will look for template name with _box.html suffixed when rendering notification contents.

The request.user.notifications.active is just used to show an example of notification queryset, you can use any other way to supply a QuerySet of your choice.

include_notify_js_variables

This tag uses notifications/includes/js_variables.html to include a template populated with JS variables and functions. You can override the values of any JS variables by creating your own version of js_variables.html template.

To include JS variables for AJAX notification support, do this:

{% load notification_tags %}
{% include_notify_js_variables %}

This template inclusion includes three javascript files from the template includes directory, they are:

mark_success.js
mark_all_success.js
delete_success.js
update_success.js

All of them are nothing but javascript function declarations which are supposed to run when a JQuery AJAX request is successfully completed.

user_notifications

The user_notifications tag is a shortcut to the render_notifications tag. It directly renders the notifications of the logged-in user on the specified target.

You can use this tag like this:

{% load notification_tags %}
{% user_notifications %}

This tag renders active notifications of the user by using something like request.user.notifications.active().

Just like render_notifications it also takes rendering target as an optional argument. You can specify rendering target like this:

{% load notification_tags %}
{% user_notifications for box %}

By default, it’ll use ‘page’ as the rendering target and use full page notification rending template corresponding to the nf_type of the template.

And other things…

It will be best to Read the Docs instead of expecting every thing from a quick guide :)

TODO List

  • Add notification concatenation support.
    • Notification concatenation is what facebook does when you read a notification like Bob and 18 others commented on your blogpost.

    • This will require non-anonymous activity stream field.

    • I’ve to either remove the anonymous notification support or find another way to implement this feature.

    • work in progress!

  • Convert Function based views to Class Based views.

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

django-notify-x2-0.5.1.tar.gz (36.0 kB view details)

Uploaded Source

Built Distribution

django_notify_x2-0.5.1-py2-none-any.whl (47.0 kB view details)

Uploaded Python 2

File details

Details for the file django-notify-x2-0.5.1.tar.gz.

File metadata

File hashes

Hashes for django-notify-x2-0.5.1.tar.gz
Algorithm Hash digest
SHA256 2c0093e20f1293f17f0cf27b88dbfac7d614d68ae75f8fccef40b67d879cb030
MD5 6ffc670fe803f3074073e5ae54e35a33
BLAKE2b-256 c626082b1989c0667d93d486790c3e28b4fef707ff333cc0b2839b5eb2c77964

See more details on using hashes here.

File details

Details for the file django_notify_x2-0.5.1-py2-none-any.whl.

File metadata

File hashes

Hashes for django_notify_x2-0.5.1-py2-none-any.whl
Algorithm Hash digest
SHA256 198cc504b8bdc66296e93e93dd9fe6ed653e13df9f53e4407f04b3df8c3f1059
MD5 d2b9c51f556762754de542be44b5fb92
BLAKE2b-256 a52d357fea607b13b1740929ab7f75c8cdab46d2f26203e1f9a2290562eefe5c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page