Skip to main content

A plug and play package to handle push devices and push notifications for services such as ZeroPush and Urban Airship

Project description

This package makes it easy to support Push notifications. It works together with third party services such as ZeroPush.

You can easily add permissions to push devices by chaining those devices to a notification setting. For registering a new push device you can add custom permissions.

Installation

To install the package on your machine you can run the PIP install:

pip install dpnm

Configuration

First you have to add push_notifications to your installed apps:

INSTALLED_APPS = (
  ...
  'push_notifications',
)

To setup the package you have to add a DJANGO_PUSH_NOTIFICATIONS into your settings:

def Settings(Configuration):
  # ...
  DJANGO_PUSH_NOTIFICATIONS = {
      'SERVICE': 'push_notifications.services.zeropush.ZeroPushService',
      'AUTH_TOKEN': '123123123'
  }

The SERVICE Key can be set to the type of service you use. In this example we use the ZeroPushService. With the ZeroPush Service we are required to add a AUTH_TOKEN to the Configuration.

Note: Right now, only ZeroPush is available. More services will be available soon.

Usage

Register a device

To register a new device you can use the register_push_device method in utils:

from push_notifications.utils from register_push_device

token = "<The device token>"
register_push_device(user, token)

You can also pass notification permissions directly to the register_push_device method:

register_push_device(user, token, ['likes', 'comments'])

Add permissions

To add an notification permission to a push device you can use the add_permission method on the device object:

device.add_permission('likes')

Or adding multiple permissions

device.add_permissions(['likes', 'comments'])

Add all the permission for the devices that the user owns.

user.push_devices.add_permissions(['likes', 'comments'])

Remove permissions

To remove a notification permission you can use remove_permission method on the device object:

device.remove_permissions('likes')

Or removing multiple permissions

device.remove_permissions(['likes', 'comments'])

Remove all the permission for the devices that the user owns.

user.push_devices.remove_permissions(['likes', 'comments'])

Send a notification

To send a notification to a certain permission group you can call send_push_notification in utils:

from push_notifications import send_push_notification
from datetime import timedelta

send_push_notification('likes', 'This is the message', sound="annoyingSound.mp3",
                                                       badge_number=1
                                                       info={
                                                        "extra": "payload",
                                                        "in": "notification"
                                                       },
                                                       expiry=timedelta(days=30))

Description

send_push_notification(notify_type, message, **kwargs)

kwargs - sound: The sound that has to be played when sending the notification - badge_number: The badge_number that has to be displayed (iOS Only) - info: Extra payload that comes along the notification - expiry: The expiry of the notification Accepts timedelta and datetime object

Send a notification to one device

To send a notification to a specific device you can use the send_push_notification on the device object

device.send_push_notification('likes', 'This is the message', sound="annoyingSound.mp3",
                                                              badge_number=1
                                                              info={
                                                                "extra": "payload",
                                                                "in": "notification"
                                                              },
                                                              expiry=timedelta(days=30))

It accepts the same parameters as the global send_push_notification in utils.

Send a notification to one user

To send a notification to a user and all its devices you can use the send_push_notification on the push_devices name in your user object:

user.push_devices.send_push_notification('likes', 'This is the message',
                                         sound="annoyingSound.mp3",
                                         badge_number=1
                                         info={
                                           "extra": "payload",
                                           "in": "notification"
                                         },
                                         expiry=timedelta(days=30))

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

dpnm-0.1.1.tar.gz (6.5 kB view details)

Uploaded Source

File details

Details for the file dpnm-0.1.1.tar.gz.

File metadata

  • Download URL: dpnm-0.1.1.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for dpnm-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ad49c9b9c35aca3a653683c841019754c0aa561bb12970fa1fe7a7e0f0a0d62e
MD5 25b6ee7d615acbf5ed421487363cbec2
BLAKE2b-256 e1bea97a7dfbeb8cca7bdfae1466c7a1262b071e95d13ed6294088ed77ce542c

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