Giter Club home page Giter Club logo

django-scarface's Introduction

django-scarface

-----------

Send push notifications to mobile devices using Amazon SNS

Documentation Status Build Status

Documentation

https://django-scarface.readthedocs.io/

Changelog

https://github.com/dreipol/django-scarface/blob/master/CHANGELOG.MD

Project Home

https://github.com/dreipol/django-scarface

PyPi

https://pypi.python.org/pypi/django-scarface

Contributors

@browniebroke @kennydude @nanorepublica @J0hn5mith @philipplaeubli @neosergio @melbic

and many more...

Trivia

django-scarface is named after the track ‘Push it to the Limit’ featured in the movie Scarface (1983).

Scarface the movie (1983)

django-scarface's People

Contributors

browniebroke avatar chschuermann avatar kennydude avatar melbic avatar nakedsushi avatar nanorepublica avatar neosergio avatar philipplaeubli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-scarface's Issues

Can't install django-scarface 3.2

I'm having trouble installing django-scarface 3.2. I am not sure if this is a django-scarface problem but any help would be great.

pip install django-scarface
Collecting django-scarface
  Using cached https://files.pythonhosted.org/packages/c6/ba/ceae41786d0e3de3e0e33cf503c663cd47e0921e5893194f5c5000acba15/django-scarface-3.2.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/y6/y3twpy9557xb2d9mvwpcymh00000gn/T/pip-install-e2xdk8fn/django-scarface/setup.py", line 31, in <module>
        version=get_version("django_scarface", "__init__.py"),
      File "/private/var/folders/y6/y3twpy9557xb2d9mvwpcymh00000gn/T/pip-install-e2xdk8fn/django-scarface/setup.py", line 21, in get_version
        version_file = open(filename).read()
    FileNotFoundError: [Errno 2] No such file or directory: '/private/var/folders/y6/y3twpy9557xb2d9mvwpcymh00000gn/T/pip-install-e2xdk8fn/django-scarface/django_scarface/__init__.py'

Django 1.10 compatibillity issue with extract_keys

When running the extract_keys command i get the following error:

Traceback (most recent call last):
  File "./manage.py", line 24, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 208, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 40, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/usr/local/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/usr/local/lib/python2.7/site-packages/scarface/management/commands/extract_keys.py", line 16, in <module>
    class Command(BaseCommand):
  File "/usr/local/lib/python2.7/site-packages/scarface/management/commands/extract_keys.py", line 17, in Command
    option_list = BaseCommand.option_list + (
AttributeError: type object 'BaseCommand' has no attribute 'option_list'

option_list have been deprecated since Django 1.8. BaseCommand.add_arguments should be used instead.

Message Trimming

The current trim treshold too small. The best thing would probably be to remove the trimming anyway (or to add a warning).

Setting up

I am having a really really tough time getting this to work. The documentation is incomplete.

What I have done so far:
pip install scarface
add 'scarface' in INSTALLED_APPS under settings.py
add the following constants in settings.py:

  1. AWS_ACCESS_KEY = 'MYKEYSTRING'
  2. AWS_SECRET_ACCESS_KEY = 'MYSECRETSTRING'
  3. SCARFACE_REGION_NAME = 'us-east-1'

Under admin console I tried to add a new app and add platforms. Tried making topics. Nothing ends up on my AWS account.

Platform principal/credential fields can't hold certificates

Hi,

First of all, thank you for sharing this lib. Great stuff.

I'm not sure if I'm doing something wrong or what, but I'm trying to create a new APNS Platform with the following code:

apns_platform = Platform.objects.create(
    platform='APNS',
    application=app,
    credential=getattr(settings, 'SCARFACE_APNS_PRIVATE_KEY', ''),
    principal=getattr(settings, 'SCARFACE_APNS_CERTIFICATE', ''),
)

I'm having issues because the fields credential and principal have a max_length of 255, as defined in the models.py file, but the certificate and private key content is a lot bigger than that. If I manually modify those fields in my database, then it works fine.

Is there another way to create a platform without having to store that info in the database? Or can I make a PR to increase the max_length of those fields?

Thanks!

SyntaxError: invalid syntax

Getting the following syntax error on install and when trying to run migrations:

File "/usr/local/lib/python2.7/dist-packages/scarface/platform_strategy.py", line 38
class PlatformStrategy(metaclass=ABCMeta):
^
SyntaxError: invalid syntax

Device and platform registration error.

following the tutorial at readthedocs

device.register()

{"Error":{"Code":"InvalidParameter","Message":"Invalid parameter: PlatformApplicationArn Reason: An ARN must have at least 6 elements, not 1","Type":"Sender"}

Incorrect use of sys.getsizeof in trim_message

In platform_strategy.py:

    def trim_message(self, message):
        import sys
        trim_length = SCARFACE_DEFAULT_MESSAGE_TRIM_LENGTH
        if hasattr(settings, 'SCARFACE_MESSAGE_TRIM_LENGTH'):
            trim_length = settings.SCARFACE_MESSAGE_TRIM_LENGTH

        if sys.getsizeof(message) > trim_length:
            while sys.getsizeof(message) > trim_length:
                message = message[:-3]
            message += '...'
        return message

Usage of sys.getsizeof is fundamentally incorrect to measuring message length. getsizeof returns the internal size of the Python object, not the actual encoded size of the final message. TL;DR; it kind of works for ascii, but utterly breaks down for unicode strings.

Here's a quick demonstration from an interactive shell:

>>> sys.getsizeof('') # Basic empty string takes up 49 bytes
49
>>> sys.getsizeof('For ascii string it kind of works, but not really')
98
>>> sys.getsizeof('Let\'s add some ünicode to themix, 👌🏻')
220
>>> # Quickly the sizeof spikes, as it is the internal representation after all.
>>> # Let's try again by not relying on how the string is implemented behind the
>>> # scenes. Instead we encode the string to a byte array, which most likely
>>> # has less magic and grows in size more predictably.
>>> sys.getsizeof('For ascii string it kind of works, but not really'.encode('utf8'))
82
>>> sys.getsizeof('Let\'s add some ünicode to themix, 👌🏻'.encode('utf8'))
76
>>> # Much better, but in this context, getsizeof really shouldn't be used,
>>> # instead we should be counting the bytes that will be actually used up
>>> # when sending the pushes.
>>> len('For ascii string it kind of works, but not really'.encode('utf8'))
49
>>> len('Let\'s add some ünicode to themix, 👌🏻'.encode('utf8'))
43

application_plattform.register(), with BotoServerError

Additional help is needed...
While this command is executed: application_plattform.register(),
I am getting this error:
Exception Type: BotoServerError
Exception Value:

BotoServerError: 400 Bad Request
{"Error":{"Code":"InvalidParameter","Message":"Invalid parameter: PlatformPrincipal not valid.","Type":"Sender"},"RequestId":"d027b359-0dd4-5296-9dd9-fe748596113c"}
Exception Location: C:\Python27\lib\site-packages\boto\sns\connection.py in _make_request, line 765

Any idea?
Thanks

global name 'APNApplication' is not defined Error

I am using the Scarface Framework and getting this error: global name 'APNApplication' is not defined. The code is:

def register(self, request, pk=None):  
    """
    registers the device to sns
    :param your_device_instance: the device
    :param token: the push token or the registration id
    """
    device = self.get_object()
    token = device.token
    # get the correct notification plattform
    application_plattform = APNApplication()
   # 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(Device.dealer.full_name)) 

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

Can you help here? do you have any idea what could be the problem?
Thanks

Support for rich push notification

Hello,

I'm trying to implement rich push notification. I tried to override the format_payload method and added 'mutable-content': True to the aps dictionary. The data that is being posted to the self._make_request('Publish', params, '/', 'POST') has the mutable-content in it but for some reason the notification that come through the device seems to be missing the parameter. It worked initially for few days before it stopped. Can you please look into this?

BotoServerError: 400 Bad Request

When using the code in your docs to register a device, I have no problem registering a new device. However, I'm running into a problem where if I log out and log back in as a different user, I get the following error.

{"Error":{"Code":"InvalidParameter","Message":"Invalid parameter: Token Reason: Endpoint arn:aws:sns:us-east-1:339077083280:endpoint/XXXXXXXX already exists with the same Token, but different attributes.","Type":"Sender"},"RequestId":"XXXXXXXX"}

I got rid of the custom user attributes and I'm just passing along the token to sns_device.register_or_update like so:

sns_device.register_or_update(new_token=token)

but I'm still getting the same error. Thanks for the help!

extract_keys management command

The command extract_keys listed on docs does not work for me, when i run it gives the following traceback:

Traceback (most recent call last):
File "manage.py", line 10, in
execute_from_command_line(sys.argv)
File "/Library/Python/2.7/site-packages/django/core/management/init.py", line 385, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/django/core/management/init.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(_args, *_options.dict)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(_args, *_options)
File "/Library/Python/2.7/site-packages/scarface/management/commands/extract_keys.py", line 44, in handle
groups = re.search(regex, result).groupdict()
AttributeError: 'NoneType' object has no attribute 'groupdict'

Facing issues with sending rich notifications for ios

I have been trying to send rich notifications to ios, I have the extra payload which we have to send to apns to receive rich notifications.
But the ios device unable to detect whether the notifications is normal or rich notification.

Am I building the PushMessage correctly if not do let me know what to change thanks.

return PushMessage(
        context=json.dumps(data),
        context_id='none',
        has_new_content=True,
        message=alert,
        sound="default",
        badge_count=1,
        extra_payload={'mutable-content': True},
    )

Add a better way to migrate platform applications

Certificats need to be replaced in the AWS/SNS console an can not be changed only in the settings.
Ideally there was a migration system or a management command in place to handle these kind of situations.

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.