fcm-django


Namefcm-django JSON
Version 0.2.4 PyPI version JSON
home_pagehttps://github.com/xtrinch/fcm-django
SummarySend push notifications to mobile devices through FCM in Django.
upload_time2017-01-11 20:07:41
maintainer
docs_urlNone
authorxTrinch
requires_python
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
Coveralis test coverage No Coveralis.
            fcm-django
=========================


.. image:: https://badge.fury.io/py/fcm-django.svg
    :target: https://badge.fury.io/py/fcm-django
.. image:: https://img.shields.io/pypi/dm/fcm-django.svg
   :target: https://pypi.python.org/pypi/fcm-django/
    
Django app for Firebase Cloud Messaging. Used as an unified platform for sending push notifications to mobile devices (android / ios). Developed with the help of https://github.com/olucurious/PyFCM

FCMDevice model fields
 - registration_id (required - is FCM token)
 - name (optional)
 - active (default: true)
 - user (optional)
 - device_id (optional - can be used to uniquely identify devices)
 - type ('android' or 'ios')

Functionality:
 - all necessary migrations
 - model admins for django admin
 - admin actions for testing single and bulk notification sending
 - automatic device pruning: devices to which notifications fail to send are marked as inactive
 - Django rest framework viewsets

Setup
-----
You can install the library directly from pypi using pip:

	$ pip install fcm-django


Edit your settings.py file:

.. code-block:: python

	INSTALLED_APPS = (
		...
		"fcm_django"
	)

	FCM_DJANGO_SETTINGS = {
		"FCM_SERVER_KEY": "[your api key]"
	}

Native Django migrations are in use. ``manage.py migrate`` will install and migrate all models.

Messages
--------

You can read more about different types of messages here_.

.. _here: https://firebase.google.com/docs/cloud-messaging/concept-options

In short, there are two types: notifications and data messages. 

Notification:

.. code-block:: json

	{
	    "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
	    "notification" : {
	      "body" : "great match!",
	      "title" : "Portugal vs. Denmark",
	      "icon" : "myicon"
	    }
	}
	
Data message:

.. code-block:: json

	{
	   "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
	   "data" : {
	     "Nick" : "Mario",
	     "body" : "great match!",
	     "Room" : "PortugalVSDenmark"
	   },
	}

As in the following example, you can send either a notification, a data message, or both.

Sending messages
----------------

.. code-block:: python

	from fcm_django.models import FCMDevice
	
	device = FCMDevice.objects.all().first()

	device.send_message("Title", "Message")
	device.send_message(data={"test": "test"})
	device.send_message(title="Title", body="Message", icon=..., data={"test": "test"})

Sending messages in bulk
------------------------

.. code-block:: python

	from fcm_django.models import FCMDevice
	
	devices = FCMDevice.objects.all()
	
	devices.send_message(title="Title", body="Message")
	devices.send_message(title="Title", body="Message", data={"test": "test"})
	devices.send_message(data={"test": "test"})

Django REST Framework (DRF) support
-----------------------------------
Viewsets come in two different varieties:

- ``FCMDeviceViewSet``

	- Permissions as specified in settings (``AllowAny`` by default, which is not recommended)
	- A device may be registered without associating it with a user
	- Will not allow duplicate registration_id's

- ``FCMDeviceAuthorizedViewSet``

	- Permissions are ``IsAuthenticated`` and custom permission ``IsOwner``, which will only allow the ``request.user`` to get and update devices that belong to that user
	- Requires a user to be authenticated, so all devices will be associated with a user
	- Will allow duplicate registration_id's for different users, so you are responsible for cleanup (if that is generally perceived as undesired behaviour or if the package itself should be doing the cleanup, open an issue or email me)

Routes can be added one of two ways:

- Routers_ (include all views)

http://www.django-rest-framework.org/tutorial/6-viewsets-and-routers#using-routers

.. code-block:: python

	from fcm_django.api.rest_framework import FCMDeviceAuthorizedViewSet
	
	from rest_framework.routers import DefaultRouter

	router = DefaultRouter()
	
	router.register(r'devices', FCMDeviceAuthorizedViewSet)

	urlpatterns = patterns('',
		# URLs will show up at <api_root>/devices
		url(r'^', include(router.urls)),
		# ...
	)
	
- Using as_view_ (specify which views to include)

http://www.django-rest-framework.org/tutorial/6-viewsets-and-routers#binding-viewsets-to-urls-explicitly

.. code-block:: python

	from fcm_django.api.rest_framework import FCMDeviceAuthorizedViewSet

	urlpatterns = patterns('',
		# Only allow creation of devices by authenticated users
		url(r'^devices?$', FCMDeviceAuthorizedViewSet.as_view({'post': 'create'}), name='create_fcm_device'),
		# ...
	)


Python 3 support
----------------
``fcm-django`` is fully compatible with Python 3.4 & 3.5


Acknowledgments
----------------
https://github.com/jleclanche/django-push-notifications

Need help, have any questions, suggestions?
----------------
Submit an issue/PR or email me at mojca.rojko@gmail.com

            

Raw data

            {
    "maintainer": "", 
    "docs_url": null, 
    "requires_python": "", 
    "maintainer_email": "", 
    "cheesecake_code_kwalitee_id": null, 
    "coveralis": false, 
    "keywords": "", 
    "upload_time": "2017-01-11 20:07:41", 
    "author": "xTrinch", 
    "home_page": "https://github.com/xtrinch/fcm-django", 
    "github_user": "xtrinch", 
    "download_url": "https://pypi.python.org/packages/cb/d1/024daa30e25dc049192380bc5f0dfe47aac7ae2bec686bda87f50964ba0a/fcm-django-0.2.4.tar.gz", 
    "platform": "UNKNOWN", 
    "version": "0.2.4", 
    "cheesecake_documentation_id": null, 
    "description": "fcm-django\n=========================\n\n\n.. image:: https://badge.fury.io/py/fcm-django.svg\n    :target: https://badge.fury.io/py/fcm-django\n.. image:: https://img.shields.io/pypi/dm/fcm-django.svg\n   :target: https://pypi.python.org/pypi/fcm-django/\n    \nDjango app for Firebase Cloud Messaging. Used as an unified platform for sending push notifications to mobile devices (android / ios). Developed with the help of https://github.com/olucurious/PyFCM\n\nFCMDevice model fields\n - registration_id (required - is FCM token)\n - name (optional)\n - active (default: true)\n - user (optional)\n - device_id (optional - can be used to uniquely identify devices)\n - type ('android' or 'ios')\n\nFunctionality:\n - all necessary migrations\n - model admins for django admin\n - admin actions for testing single and bulk notification sending\n - automatic device pruning: devices to which notifications fail to send are marked as inactive\n - Django rest framework viewsets\n\nSetup\n-----\nYou can install the library directly from pypi using pip:\n\n\t$ pip install fcm-django\n\n\nEdit your settings.py file:\n\n.. code-block:: python\n\n\tINSTALLED_APPS = (\n\t\t...\n\t\t\"fcm_django\"\n\t)\n\n\tFCM_DJANGO_SETTINGS = {\n\t\t\"FCM_SERVER_KEY\": \"[your api key]\"\n\t}\n\nNative Django migrations are in use. ``manage.py migrate`` will install and migrate all models.\n\nMessages\n--------\n\nYou can read more about different types of messages here_.\n\n.. _here: https://firebase.google.com/docs/cloud-messaging/concept-options\n\nIn short, there are two types: notifications and data messages. \n\nNotification:\n\n.. code-block:: json\n\n\t{\n\t    \"to\" : \"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...\",\n\t    \"notification\" : {\n\t      \"body\" : \"great match!\",\n\t      \"title\" : \"Portugal vs. Denmark\",\n\t      \"icon\" : \"myicon\"\n\t    }\n\t}\n\t\nData message:\n\n.. code-block:: json\n\n\t{\n\t   \"to\" : \"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...\",\n\t   \"data\" : {\n\t     \"Nick\" : \"Mario\",\n\t     \"body\" : \"great match!\",\n\t     \"Room\" : \"PortugalVSDenmark\"\n\t   },\n\t}\n\nAs in the following example, you can send either a notification, a data message, or both.\n\nSending messages\n----------------\n\n.. code-block:: python\n\n\tfrom fcm_django.models import FCMDevice\n\t\n\tdevice = FCMDevice.objects.all().first()\n\n\tdevice.send_message(\"Title\", \"Message\")\n\tdevice.send_message(data={\"test\": \"test\"})\n\tdevice.send_message(title=\"Title\", body=\"Message\", icon=..., data={\"test\": \"test\"})\n\nSending messages in bulk\n------------------------\n\n.. code-block:: python\n\n\tfrom fcm_django.models import FCMDevice\n\t\n\tdevices = FCMDevice.objects.all()\n\t\n\tdevices.send_message(title=\"Title\", body=\"Message\")\n\tdevices.send_message(title=\"Title\", body=\"Message\", data={\"test\": \"test\"})\n\tdevices.send_message(data={\"test\": \"test\"})\n\nDjango REST Framework (DRF) support\n-----------------------------------\nViewsets come in two different varieties:\n\n- ``FCMDeviceViewSet``\n\n\t- Permissions as specified in settings (``AllowAny`` by default, which is not recommended)\n\t- A device may be registered without associating it with a user\n\t- Will not allow duplicate registration_id's\n\n- ``FCMDeviceAuthorizedViewSet``\n\n\t- Permissions are ``IsAuthenticated`` and custom permission ``IsOwner``, which will only allow the ``request.user`` to get and update devices that belong to that user\n\t- Requires a user to be authenticated, so all devices will be associated with a user\n\t- Will allow duplicate registration_id's for different users, so you are responsible for cleanup (if that is generally perceived as undesired behaviour or if the package itself should be doing the cleanup, open an issue or email me)\n\nRoutes can be added one of two ways:\n\n- Routers_ (include all views)\n\nhttp://www.django-rest-framework.org/tutorial/6-viewsets-and-routers#using-routers\n\n.. code-block:: python\n\n\tfrom fcm_django.api.rest_framework import FCMDeviceAuthorizedViewSet\n\t\n\tfrom rest_framework.routers import DefaultRouter\n\n\trouter = DefaultRouter()\n\t\n\trouter.register(r'devices', FCMDeviceAuthorizedViewSet)\n\n\turlpatterns = patterns('',\n\t\t# URLs will show up at <api_root>/devices\n\t\turl(r'^', include(router.urls)),\n\t\t# ...\n\t)\n\t\n- Using as_view_ (specify which views to include)\n\nhttp://www.django-rest-framework.org/tutorial/6-viewsets-and-routers#binding-viewsets-to-urls-explicitly\n\n.. code-block:: python\n\n\tfrom fcm_django.api.rest_framework import FCMDeviceAuthorizedViewSet\n\n\turlpatterns = patterns('',\n\t\t# Only allow creation of devices by authenticated users\n\t\turl(r'^devices?$', FCMDeviceAuthorizedViewSet.as_view({'post': 'create'}), name='create_fcm_device'),\n\t\t# ...\n\t)\n\n\nPython 3 support\n----------------\n``fcm-django`` is fully compatible with Python 3.4 & 3.5\n\n\nAcknowledgments\n----------------\nhttps://github.com/jleclanche/django-push-notifications\n\nNeed help, have any questions, suggestions?\n----------------\nSubmit an issue/PR or email me at mojca.rojko@gmail.com\n", 
    "lcname": "fcm-django", 
    "bugtrack_url": null, 
    "github": true, 
    "name": "fcm-django", 
    "license": "", 
    "travis_ci": false, 
    "github_project": "fcm-django", 
    "summary": "Send push notifications to mobile devices through FCM in Django.", 
    "split_keywords": [], 
    "author_email": "mojca.rojko@gmail.com", 
    "urls": [
        {
            "has_sig": false, 
            "upload_time": "2017-01-11T20:07:41", 
            "comment_text": "", 
            "python_version": "source", 
            "url": "https://pypi.python.org/packages/cb/d1/024daa30e25dc049192380bc5f0dfe47aac7ae2bec686bda87f50964ba0a/fcm-django-0.2.4.tar.gz", 
            "md5_digest": "afea94f497e19fe8f4437cfc516e5797", 
            "downloads": 0, 
            "filename": "fcm-django-0.2.4.tar.gz", 
            "packagetype": "sdist", 
            "path": "cb/d1/024daa30e25dc049192380bc5f0dfe47aac7ae2bec686bda87f50964ba0a/fcm-django-0.2.4.tar.gz", 
            "size": 8905
        }, 
        {
            "has_sig": false, 
            "upload_time": "2017-01-11T20:07:39", 
            "comment_text": "", 
            "python_version": "py2.py3", 
            "url": "https://pypi.python.org/packages/20/ab/cf26218790d8b6b3f3d8d490e847d8e71904569674f3b114247684414188/fcm_django-0.2.4-py2.py3-none-any.whl", 
            "md5_digest": "b57a40eb6a1b72fc5def991d1b015a4f", 
            "downloads": 0, 
            "filename": "fcm_django-0.2.4-py2.py3-none-any.whl", 
            "packagetype": "bdist_wheel", 
            "path": "20/ab/cf26218790d8b6b3f3d8d490e847d8e71904569674f3b114247684414188/fcm_django-0.2.4-py2.py3-none-any.whl", 
            "size": 11706
        }
    ], 
    "_id": null, 
    "cheesecake_installability_id": null
}