Package: django-push-notifications-manager
This package makes it easy to support Push notifications. It works
together with third party services such asZeroPush.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.InstallationTo install the package on your machine you can run the PIP install:pip install django-push-notifications-managerConfigurationFirst you have to addpush_notificationsto your installed apps:INSTALLED_APPS=(...'push_notifications',)To setup the package you have to add aDJANGO_PUSH_NOTIFICATIONSinto your settings:defSettings(Configuration):# ...DJANGO_PUSH_NOTIFICATIONS={'SERVICE':'push_notifications.services.zeropush.ZeroPushService','AUTH_TOKEN':'123123123'}TheSERVICEKey can be set to the type of service you use. In this
example we use theZeroPushService. With theZeroPushService we
are required to add aAUTH_TOKENto theConfiguration.Note: Right now, onlyZeroPushis available. More services will
be available soon.UsageRegister a deviceTo register a new device you can use theregister_push_devicemethod
inutils:frompush_notifications.utilsfromregister_push_devicetoken="<The device token>"register_push_device(user,token)You can also pass notification permissions directly to theregister_push_devicemethod:register_push_device(user,token,['likes','comments'])Add permissionsTo add an notification permission to a push device you can use theadd_permissionmethod on thedeviceobject:device.add_permission('likes')Or adding multiple permissionsdevice.add_permissions(['likes','comments'])Add all the permission for the devices that the user owns.user.push_devices.add_permissions(['likes','comments'])Remove permissionsTo remove a notification permission you can useremove_permissionmethod on thedeviceobject:device.remove_permissions('likes')Or removing multiple permissionsdevice.remove_permissions(['likes','comments'])Remove all the permission for the devices that the user owns.user.push_devices.remove_permissions(['likes','comments'])Send a notificationTo send a notification to a certain permission group you can callsend_push_notificationinutils:frompush_notificationsimportsend_push_notificationfromdatetimeimporttimedeltasend_push_notification('likes','This is the message',sound="annoyingSound.mp3",badge_number=1info={"extra":"payload","in":"notification"},expiry=timedelta(days=30))Descriptionsend_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 notificationAccepts
timedelta and datetime objectSend a notification to one deviceTo send a notification to a specific device you can use thesend_push_notificationon thedeviceobjectdevice.send_push_notification('likes','This is the message',sound="annoyingSound.mp3",badge_number=1info={"extra":"payload","in":"notification"},expiry=timedelta(days=30))It accepts the same parameters as the globalsend_push_notificationinutils.Send a notification to one userTo send a notification to a user and all its devices you can use thesend_push_notificationon thepush_devicesname in your user
object:user.push_devices.send_push_notification('likes','This is the message',sound="annoyingSound.mp3",badge_number=1info={"extra":"payload","in":"notification"},expiry=timedelta(days=30))