combo/combo/apps/publik/views.py

47 lines
2.0 KiB
Python

# 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
from django.utils.translation import ugettext_lazy as _
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),
'url': service['url'],
'backoffice_menu_url': service['backoffice-menu-url'],
})
response_vars = {
'PUBLIK_PORTAL_AGENT_URL': request.build_absolute_uri('/'),
'PUBLIK_PORTAL_AGENT_TITLE': settings.TEMPLATE_VARS.get('site_title') or _('Portal Agent'),
'PUBLIK_PORTAL_AGENT_EXTRA_CSS': settings.TEMPLATE_VARS.get(
'portal_agent_extra_css'),
'COMBO_KNOWN_SERVICES': services,
}
response_body = '\n'.join(
['var %s = %s;' % (x[0], json.dumps(x[1])) for x in response_vars.items()])
return HttpResponse(response_body, content_type='text/javascript')