pwa: add possibility to use a template for manifest.json (#24400)
This commit is contained in:
parent
2ffdb41f93
commit
b09080980d
|
@ -0,0 +1,26 @@
|
|||
# combo - content management system
|
||||
# Copyright (C) 2015-2018 Entr'ouvert
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import django.apps
|
||||
|
||||
class AppConfig(django.apps.AppConfig):
|
||||
name = 'combo.apps.pwa'
|
||||
|
||||
def get_before_urls(self):
|
||||
from . import urls
|
||||
return urls.urlpatterns
|
||||
|
||||
default_app_config = 'combo.apps.pwa.AppConfig'
|
|
@ -0,0 +1,21 @@
|
|||
# combo - content management system
|
||||
# Copyright (C) 2015-2018 Entr'ouvert
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from django.conf.urls import url
|
||||
|
||||
from .views import manifest_json
|
||||
|
||||
urlpatterns = [url('^manifest.json', manifest_json)]
|
|
@ -0,0 +1,25 @@
|
|||
# combo - content management system
|
||||
# Copyright (C) 2015-2018 Entr'ouvert
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from django.http import HttpResponse, Http404
|
||||
from django.template.loader import get_template, TemplateDoesNotExist
|
||||
|
||||
def manifest_json(request, *args, **kwargs):
|
||||
try:
|
||||
template = get_template('combo/manifest.json')
|
||||
except TemplateDoesNotExist:
|
||||
raise Http404()
|
||||
return HttpResponse(template.render({}, request), content_type='application/json')
|
|
@ -76,6 +76,7 @@ INSTALLED_APPS = (
|
|||
'combo.apps.usersearch',
|
||||
'combo.apps.maps',
|
||||
'combo.apps.calendar',
|
||||
'combo.apps.pwa',
|
||||
'haystack',
|
||||
'xstatic.pkg.josefinsans',
|
||||
'xstatic.pkg.leaflet',
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"name": "test"
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
import os
|
||||
import pytest
|
||||
|
||||
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'
|
Loading…
Reference in New Issue