Projet

Général

Profil

0001-pwa-add-django-push-notification-and-compatibility-t.patch

Anonyme, 24 août 2018 17:21

Télécharger (4,6 ko)

Voir les différences:

Subject: [PATCH 1/6] pwa: add django-push-notification and compatibility to
 Django 1.11 (#25462)

 combo/settings.py | 42 +++++++++++++++++++++++++++++++++++++++++-
 requirements.txt  |  2 +-
 tests/test_pwa.py | 19 +++++++++++--------
 tox.ini           |  1 +
 4 files changed, 54 insertions(+), 10 deletions(-)
combo/settings.py
24 24
"""
25 25

  
26 26
import os
27

  
28
import django
27 29
from django.conf import global_settings
28 30
from django.utils.translation import ugettext_lazy as _
29 31

  
......
75 77
    'combo.apps.usersearch',
76 78
    'combo.apps.maps',
77 79
    'combo.apps.calendar',
78
    'combo.apps.pwa',
79 80
    'haystack',
80 81
    'xstatic.pkg.josefinsans',
81 82
    'xstatic.pkg.leaflet',
......
84 85
    'xstatic.pkg.leaflet_markercluster',
85 86
)
86 87

  
88
if django.VERSION >= (1, 11):
89
    INSTALLED_APPS += (
90
        'push_notifications',
91
        'combo.apps.pwa',
92
    )
93

  
87 94
MIDDLEWARE_CLASSES = (
88 95
    'combo.middleware.GlobalRequestMiddleware',
89 96
    'django.contrib.sessions.middleware.SessionMiddleware',
......
312 319
BOOKING_CALENDAR_CELL_ENABLED = False
313 320
NEWSLETTERS_CELL_ENABLED = False
314 321

  
322
# How-to configure VAPID
323
#   $ pip install pywebpush py-vapid
324
# * Create a temporary file (claim.json) like this:
325
#
326
#   {
327
#     "sub": "mailto: android@entrouvert.com",
328
#     "aud": "https://fcm.googleapis.com"
329
#   }
330
#
331
# * Generate public and private keys:
332
#
333
#   $ vapid --sign claim.json
334
#
335
# * Generate client public key (applicationServerKey)
336
#
337
#   $ vapid --applicationServerKey
338
#
339
#       Application Server Key = BEFuGfKKEFp-kEBMxAIw7ng8HeH_QwnH5_h55ijKD4FRvgdJU1GVlDo8K5U5ak4cMZdQTUJlkA34llWF0xHya70
340
#
341
# * Configure settings:
342
# ** ``APP_SERVER_KEY``: Copy the value output of the previous command to your local_settings.py or to the multinenant configuration combo_settings.py
343
# ** do not touch WP_CLAIMS
344

  
345
PUSH_NOTIFICATIONS_SETTINGS = {
346
    'WP_PRIVATE_KEY': os.path.join(BASE_DIR, "private_key.pem"), # file generated by the vapid command (from py-vapid)
347
    'WP_CLAIMS': {
348
        "sub": "mailto: android@entrouvert.com" # 'sub' *must* be the only item, do not touch this, you could break VAPID protocol
349
    },
350
    'WP_ERROR_TIMEOUT': 10, # timeout for the request on the push server
351
    'UPDATE_ON_DUPLICATE_REG_ID': True,
352
    'MESSAGE_TAG': 'Publik PWA module', # default tag (for optionnal client-side grouping notification together)
353
}
354

  
315 355
local_settings_file = os.environ.get('COMBO_SETTINGS_FILE',
316 356
        os.path.join(os.path.dirname(__file__), 'local_settings.py'))
317 357
if os.path.exists(local_settings_file):
requirements.txt
1
Django>=1.8, <1.9
1
Django>=1.8, <1.12
2 2
django-ckeditor<4.5.3
3 3
gadjo
4 4
feedparser
tests/test_pwa.py
1 1
import os
2 2
import pytest
3 3

  
4
import django
4 5
from django.conf import settings
5 6
from django.test import override_settings
6 7

  
7 8
pytestmark = pytest.mark.django_db
8 9

  
9
def test_manifest_json(app):
10
    app.get('/manifest.json', status=404)
11 10

  
12
    templates_settings = [settings.TEMPLATES[0].copy()]
13
    templates_settings[0]['DIRS'] = ['%s/templates-1' % os.path.abspath(os.path.dirname(__file__))]
14
    with override_settings(TEMPLATES=templates_settings):
15
        assert app.get('/manifest.json', status=200).json['name'] == 'test'
11
if django.VERSION >= (1, 11):
12
    def test_manifest_json(app):
13
        app.get('/manifest.json', status=404)
16 14

  
17
def test_service_worker(app):
18
    app.get('/service-worker.js', status=200)
15
        templates_settings = [settings.TEMPLATES[0].copy()]
16
        templates_settings[0]['DIRS'] = ['%s/templates-1' % os.path.abspath(os.path.dirname(__file__))]
17
        with override_settings(TEMPLATES=templates_settings):
18
            assert app.get('/manifest.json', status=200).json['name'] == 'test'
19

  
20
    def test_service_worker(app):
21
        app.get('/service-worker.js', status=200)
tox.ini
12 12
deps =
13 13
  django18: django>=1.8,<1.9
14 14
  django111: django>=1.11,<1.12
15
  django111: django-push-notifications
15 16
  pytest-cov
16 17
  pytest-django
17 18
  pytest-freezegun
18
-