pwa: add django-push-notification and compatibility to Django 1.11 (#25462)

This commit is contained in:
Elias Showk 2018-08-23 16:25:41 +02:00
parent 35ac62ff50
commit 1a570ea805
4 changed files with 54 additions and 10 deletions

View File

@ -24,6 +24,8 @@ and to disable DEBUG mode in production.
"""
import os
import django
from django.conf import global_settings
from django.utils.translation import ugettext_lazy as _
@ -75,7 +77,6 @@ INSTALLED_APPS = (
'combo.apps.usersearch',
'combo.apps.maps',
'combo.apps.calendar',
'combo.apps.pwa',
'haystack',
'xstatic.pkg.josefinsans',
'xstatic.pkg.leaflet',
@ -84,6 +85,12 @@ INSTALLED_APPS = (
'xstatic.pkg.leaflet_markercluster',
)
if django.VERSION >= (1, 11):
INSTALLED_APPS += (
'push_notifications',
'combo.apps.pwa',
)
MIDDLEWARE_CLASSES = (
'combo.middleware.GlobalRequestMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
@ -312,6 +319,39 @@ WCS_FORM_ASSET_SLOTS = {}
BOOKING_CALENDAR_CELL_ENABLED = False
NEWSLETTERS_CELL_ENABLED = False
# How-to configure VAPID
# $ pip install pywebpush py-vapid
# * Create a temporary file (claim.json) like this:
#
# {
# "sub": "mailto: android@entrouvert.com",
# "aud": "https://fcm.googleapis.com"
# }
#
# * Generate public and private keys:
#
# $ vapid --sign claim.json
#
# * Generate client public key (applicationServerKey)
#
# $ vapid --applicationServerKey
#
# Application Server Key = BEFuGfKKEFp-kEBMxAIw7ng8HeH_QwnH5_h55ijKD4FRvgdJU1GVlDo8K5U5ak4cMZdQTUJlkA34llWF0xHya70
#
# * Configure settings:
# ** ``APP_SERVER_KEY``: Copy the value output of the previous command to your local_settings.py or to the multinenant configuration combo_settings.py
# ** do not touch WP_CLAIMS
PUSH_NOTIFICATIONS_SETTINGS = {
'WP_PRIVATE_KEY': os.path.join(BASE_DIR, "private_key.pem"), # file generated by the vapid command (from py-vapid)
'WP_CLAIMS': {
"sub": "mailto: android@entrouvert.com" # 'sub' *must* be the only item, do not touch this, you could break VAPID protocol
},
'WP_ERROR_TIMEOUT': 10, # timeout for the request on the push server
'UPDATE_ON_DUPLICATE_REG_ID': True,
'MESSAGE_TAG': 'Publik PWA module', # default tag (for optionnal client-side grouping notification together)
}
local_settings_file = os.environ.get('COMBO_SETTINGS_FILE',
os.path.join(os.path.dirname(__file__), 'local_settings.py'))
if os.path.exists(local_settings_file):

View File

@ -1,4 +1,4 @@
Django>=1.8, <1.9
Django>=1.8, <1.12
django-ckeditor<4.5.3
gadjo
feedparser

View File

@ -1,18 +1,21 @@
import os
import pytest
import django
from django.conf import settings
from django.test import override_settings
pytestmark = pytest.mark.django_db
def test_manifest_json(app):
app.get('/manifest.json', status=404)
templates_settings = [settings.TEMPLATES[0].copy()]
templates_settings[0]['DIRS'] = ['%s/templates-1' % os.path.abspath(os.path.dirname(__file__))]
with override_settings(TEMPLATES=templates_settings):
assert app.get('/manifest.json', status=200).json['name'] == 'test'
if django.VERSION >= (1, 11):
def test_manifest_json(app):
app.get('/manifest.json', status=404)
def test_service_worker(app):
app.get('/service-worker.js', status=200)
templates_settings = [settings.TEMPLATES[0].copy()]
templates_settings[0]['DIRS'] = ['%s/templates-1' % os.path.abspath(os.path.dirname(__file__))]
with override_settings(TEMPLATES=templates_settings):
assert app.get('/manifest.json', status=200).json['name'] == 'test'
def test_service_worker(app):
app.get('/service-worker.js', status=200)

View File

@ -12,6 +12,7 @@ setenv =
deps =
django18: django>=1.8,<1.9
django111: django>=1.11,<1.12
django111: django-push-notifications
pytest-cov
pytest-django
pytest-freezegun