Projet

Général

Profil

0001-pwa-add-possibility-to-use-a-template-for-manifest.j.patch

Frédéric Péters, 11 juin 2018 15:30

Télécharger (5,53 ko)

Voir les différences:

Subject: [PATCH 1/2] pwa: add possibility to use a template for manifest.json
 (#24400)

 combo/apps/pwa/__init__.py            | 26 ++++++++++++++++++++++++++
 combo/apps/pwa/urls.py                | 21 +++++++++++++++++++++
 combo/apps/pwa/views.py               | 25 +++++++++++++++++++++++++
 combo/settings.py                     |  1 +
 tests/templates-1/combo/manifest.json |  3 +++
 tests/test_pwa.py                     | 15 +++++++++++++++
 6 files changed, 91 insertions(+)
 create mode 100644 combo/apps/pwa/__init__.py
 create mode 100644 combo/apps/pwa/urls.py
 create mode 100644 combo/apps/pwa/views.py
 create mode 100644 tests/templates-1/combo/manifest.json
 create mode 100644 tests/test_pwa.py
combo/apps/pwa/__init__.py
1
# combo - content management system
2
# Copyright (C) 2015-2018  Entr'ouvert
3
#
4
# This program is free software: you can redistribute it and/or modify it
5
# under the terms of the GNU Affero General Public License as published
6
# by the Free Software Foundation, either version 3 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU Affero General Public License for more details.
13
#
14
# You should have received a copy of the GNU Affero General Public License
15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16

  
17
import django.apps
18

  
19
class AppConfig(django.apps.AppConfig):
20
    name = 'combo.apps.pwa'
21

  
22
    def get_before_urls(self):
23
        from . import urls
24
        return urls.urlpatterns
25

  
26
default_app_config = 'combo.apps.pwa.AppConfig'
combo/apps/pwa/urls.py
1
# combo - content management system
2
# Copyright (C) 2015-2018  Entr'ouvert
3
#
4
# This program is free software: you can redistribute it and/or modify it
5
# under the terms of the GNU Affero General Public License as published
6
# by the Free Software Foundation, either version 3 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU Affero General Public License for more details.
13
#
14
# You should have received a copy of the GNU Affero General Public License
15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16

  
17
from django.conf.urls import url
18

  
19
from .views import manifest_json
20

  
21
urlpatterns = [url('^manifest.json', manifest_json)]
combo/apps/pwa/views.py
1
# combo - content management system
2
# Copyright (C) 2015-2018  Entr'ouvert
3
#
4
# This program is free software: you can redistribute it and/or modify it
5
# under the terms of the GNU Affero General Public License as published
6
# by the Free Software Foundation, either version 3 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU Affero General Public License for more details.
13
#
14
# You should have received a copy of the GNU Affero General Public License
15
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16

  
17
from django.http import HttpResponse, Http404
18
from django.template.loader import get_template, TemplateDoesNotExist
19

  
20
def manifest_json(request, *args, **kwargs):
21
    try:
22
        template = get_template('combo/manifest.json')
23
    except TemplateDoesNotExist:
24
        raise Http404()
25
    return HttpResponse(template.render({}, request), content_type='application/json')
combo/settings.py
76 76
    'combo.apps.usersearch',
77 77
    'combo.apps.maps',
78 78
    'combo.apps.calendar',
79
    'combo.apps.pwa',
79 80
    'haystack',
80 81
    'xstatic.pkg.josefinsans',
81 82
    'xstatic.pkg.leaflet',
tests/templates-1/combo/manifest.json
1
{
2
  "name": "test"
3
}
tests/test_pwa.py
1
import os
2
import pytest
3

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

  
7
pytestmark = pytest.mark.django_db
8

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

  
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'
0
-