From 263c667222f4ab6dac3920ec9098ad8c099156ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Thu, 21 May 2015 11:29:12 +0200 Subject: [PATCH] add combo.apps.publik, to advertise the list of known services (#7154) --- combo/apps/publik/__init__.py | 26 +++++++++++++++++++++++++ combo/apps/publik/urls.py | 21 ++++++++++++++++++++ combo/apps/publik/views.py | 36 +++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 combo/apps/publik/__init__.py create mode 100644 combo/apps/publik/urls.py create mode 100644 combo/apps/publik/views.py diff --git a/combo/apps/publik/__init__.py b/combo/apps/publik/__init__.py new file mode 100644 index 00000000..f4f3d981 --- /dev/null +++ b/combo/apps/publik/__init__.py @@ -0,0 +1,26 @@ +# combo - content management system +# Copyright (C) 2015 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 . + +import django.apps + +class AppConfig(django.apps.AppConfig): + name = 'combo.apps.publik' + + def get_before_urls(self): + from . import urls + return urls.urlpatterns + +default_app_config = 'combo.apps.publik.AppConfig' diff --git a/combo/apps/publik/urls.py b/combo/apps/publik/urls.py new file mode 100644 index 00000000..535692d8 --- /dev/null +++ b/combo/apps/publik/urls.py @@ -0,0 +1,21 @@ +# combo - content management system +# Copyright (C) 2015 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 . + +from django.conf.urls import patterns, url + +from .views import services_js + +urlpatterns = patterns('', url('^__services.js', services_js)) diff --git a/combo/apps/publik/views.py b/combo/apps/publik/views.py new file mode 100644 index 00000000..f405f316 --- /dev/null +++ b/combo/apps/publik/views.py @@ -0,0 +1,36 @@ +# combo - content management system +# Copyright (C) 2015 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 . + +import json + +from django.conf import settings +from django.http import Http404, HttpResponse + +def services_js(request, *args, **kwargs): + if not getattr(settings, 'KNOWN_SERVICES', None): + raise Http404() + services = [] + for service_id, services_dict in settings.KNOWN_SERVICES.items(): + for service_slug, service in services_dict.items(): + services.append({ + 'title': service['title'], + 'slug': service_slug, + 'service_id': service_id, + 'uniq': bool(len(services_dict) == 1), + 'backoffice_menu_url': service['backoffice-menu-url'], + }) + response_body = 'var COMBO_KNOWN_SERVICES = %s;' % json.dumps(services) + return HttpResponse(response_body, content_type='text/javascript')