add combo.apps.publik, to advertise the list of known services (#7154)

This commit is contained in:
Frédéric Péters 2015-05-21 11:29:12 +02:00
parent bbbf85a277
commit 263c667222
3 changed files with 83 additions and 0 deletions

View File

@ -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 <http://www.gnu.org/licenses/>.
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'

21
combo/apps/publik/urls.py Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
from django.conf.urls import patterns, url
from .views import services_js
urlpatterns = patterns('', url('^__services.js', services_js))

View File

@ -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 <http://www.gnu.org/licenses/>.
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')