Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

Commit

Permalink
no need to explictly define a settings file when using management com…
Browse files Browse the repository at this point in the history
…mands & improved documentation
  • Loading branch information
philipplaeubli committed Jan 6, 2015
1 parent 7274a8b commit 5de33e5
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
2 changes: 2 additions & 0 deletions django_scarface/settings/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# coding=utf-8
from local import *
68 changes: 67 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,81 @@ For GCM it's the same approach. Just create an `GCMApplication`.


### Send Push Notifications

Register a device like seen above.

Send a push message:

message = PushMessage(badge_count=1, context='url_alert', context_id='none',
has_new_content=True, message="Hello world!", sound="default")
ios_device.send(message)

If logging is enabled, all sent push messages are logged in the table scarface_pushmessage.



## Examples

### Registration
def register(your_device_instance, token):
"""
registers the device to sns
:param your_device_instance: the device
:param token: the push token or the registration id
"""

# get the correct notification plattform
if your_device_instance.is_ios():
application_plattform = APNApplication()
else:
application_plattform = GCMApplication()

#register the application
application_plattform.register()

# create the device resource with the token (may be the push token or the registration id)
sns_device = SNSDevice(application_plattform, token)

# register the device with sns or update the token/the attributes
sns_device.register_or_update(new_token=token, custom_user_data="customer_name={0}".format(your_device_instance.customer_name))

# this is importat: after updating or registration, your sns resource should have a arn. save this to your database.
if sns_device.arn:
your_device_instance.arn = sns_device.arn
your_device_instance.save()

### Send Push Notifications
def push(message, badge, targeted_devices):

"""
sends a push to the targeted devices
:param message: the text message
:param badge: the new badge count (only applies to ios
"""


# set up the application. in this scenario we can target both platforms
apns = APNApplication()
gcm = GCMApplication()

# for every targeted device...
for your_device_instance in targeted_devices:
# ...get the correct application
if your_device_instance.is_ios():
application_platform = apns
else:
application_platform = gcm

# and if your device model has a arn....
if your_device_instance.arn:

# ...create the device resource...
sns_device = SNSDevice(application_platform, your_device_instance.push_token, arn=your_device_instance.arn)
# ... and the push message...
message = PushMessage(badge_count=badge, context='push', context_id='none', has_new_content=True,
message=message, sound="default")
# ...and then send it.
sns_device.send(message)

Now have fun using this library and [push it to the limit](https://www.youtube.com/watch?v=9D-QD_HIfjA).

![the movie](scarface-movie.png)

0 comments on commit 5de33e5

Please sign in to comment.