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_SERVICES_URL = getattr(settings, 'CLOUDBAR_SERVICES_URL') CB_MENU_URL = getattr(settings, 'CLOUDBAR_MENU_URL') CB_HEIGHT = getattr(settings, 'CLOUDBAR_HEIGHT', '35') CB_BGCOLOR = getattr(settings, 'CLOUDBAR_BACKGROUND_COLOR', '#000000') CB_CODE = """ """ % {'location': CB_LOCATION, 'cookie_name': CB_COOKIE_NAME, 'services_url': CB_SERVICES_URL, 'menu_url': CB_MENU_URL, 'height': str(CB_HEIGHT), 'bg_color': CB_BGCOLOR} CB_CODE = mark_safe(CB_CODE) return { 'CLOUDBAR_ACTIVE': CB_ACTIVE, 'CLOUDBAR_LOCATION': CB_LOCATION, 'CLOUDBAR_COOKIE_NAME': CB_COOKIE_NAME, 'CLOUDBAR_SERVICES_URL': CB_SERVICES_URL, 'CLOUDBAR_MENU_URL': CB_MENU_URL, 'CLOUDBAR_CODE': CB_CODE }