from django.utils.safestring import mark_safe from django.conf import settings def cloudbar(request): """ Django context processor that applies all cloudbar settings in response context plus a ready to use pre rendered script html tag containing valid javascript code for cloudbar to display. To use it add ``synnefo.lib.context_processors.cloudbar`` in your project's ``TEMPLATE_CONTEXT_PROCESSORS setting`` (snf-webproject already does). Then in your base html template:: .... ... {% if CLOUDBAR_ACTIVE %} {{ CLOUDBAR_CODE }} {% endif %} .... """ CB_ACTIVE = getattr(settings, 'CLOUDBAR_ACTIVE', True) CB_LOCATION = getattr(settings, 'CLOUDBAR_LOCATION', '') CB_COOKIE_NAME = getattr(settings, 'CLOUDBAR_COOKIE_NAME', 'okeanos_account') CB_ACTIVE_SERVICE = getattr(settings, 'CLOUDBAR_ACTIVE_SERVICE', 'cloud') CB_SERVICES_URL = getattr(settings, 'CLOUDBAR_SERVICES_URL', '') CB_MENU_URL = getattr(settings, 'CLOUDBAR_MENU_URL', '') CB_CODE = """ """ % {'location': CB_LOCATION, 'active_service': CB_ACTIVE_SERVICE, 'cookie_name': CB_COOKIE_NAME, 'services_url': CB_SERVICES_URL, 'menu_url': CB_MENU_URL} CB_CODE = mark_safe(CB_CODE) return { 'CLOUDBAR_ACTIVE': CB_ACTIVE, 'CLOUDBAR_LOCATION': CB_LOCATION, 'CLOUDBAR_COOKIE_NAME': CB_COOKIE_NAME, 'CLOUDBAR_ACTIVE_SERVICE': CB_ACTIVE_SERVICE, 'CLOUDBAR_SERVICES_URL': CB_SERVICES_URL, 'CLOUDBAR_MENU_URL': CB_MENU_URL, 'CLOUDBAR_CODE': CB_CODE }