Revision 49044e69

b/snf-astakos-app/astakos/synnefo_settings.py
64 64
    'astakos.im.context_processors.custom_messages',
65 65
    'astakos.im.context_processors.last_login_method',
66 66
    'astakos.im.context_processors.membership_policies',
67
    'synnefo.lib.context_processors.cloudbar'
67
    'synnefo.webproject.context_processors.cloudbar'
68 68
]
69 69

  
70 70
middlware_classes = [
/dev/null
1
from django.utils.safestring import mark_safe
2
from django.conf import settings
3

  
4

  
5
def cloudbar(request):
6
    """
7
    Django context processor that applies all cloudbar settings in response
8
    context plus a ready to use pre rendered script html tag containing valid
9
    javascript code for cloudbar to display.
10

  
11
    To use it add ``synnefo.lib.context_processors.cloudbar`` in your project's
12
    ``TEMPLATE_CONTEXT_PROCESSORS setting`` (snf-webproject already does).
13

  
14
    Then in your base html template::
15

  
16
        <html>
17
        ....
18
        <head>
19
        ...
20
        {% if CLOUDBAR_ACTIVE %}
21
            {{ CLOUDBAR_CODE }}
22
        {% endif %}
23
        </head>
24
        <body>
25
        ....
26
        </body>
27
        </html>
28

  
29

  
30
    """
31

  
32
    CB_ACTIVE = getattr(settings, 'CLOUDBAR_ACTIVE', True)
33
    CB_LOCATION = getattr(settings, 'CLOUDBAR_LOCATION')
34
    CB_COOKIE_NAME = getattr(settings, 'CLOUDBAR_COOKIE_NAME',
35
            'okeanos_account')
36
    CB_SERVICES_URL = getattr(settings, 'CLOUDBAR_SERVICES_URL')
37
    CB_MENU_URL = getattr(settings, 'CLOUDBAR_MENU_URL')
38
    CB_HEIGHT = getattr(settings, 'CLOUDBAR_HEIGHT',
39
            '35')
40
    CB_BGCOLOR = getattr(settings, 'CLOUDBAR_BACKGROUND_COLOR',
41
            '#000000')
42

  
43
    CB_CODE = """
44
    <script type="text/javascript">
45
        var CLOUDBAR_LOCATION = "%(location)s";
46
        var CLOUDBAR_COOKIE_NAME = "%(cookie_name)s";
47
        var GET_SERVICES_URL = "%(services_url)s";
48
        var GET_MENU_URL = "%(menu_url)s";
49
        var CLOUDBAR_HEIGHT = '%(height)s';
50

  
51
        $(document).ready(function(){
52
            $.getScript(CLOUDBAR_LOCATION + 'cloudbar.js');
53
        });
54

  
55
    </script>
56
    <style>
57
        body {
58
            border-top: %(height)spx solid %(bg_color)s;
59
        }
60
        body .cloudbar {
61
            height: %(height)spx;
62
        }
63
    </style>
64
""" % {'location': CB_LOCATION,
65
       'cookie_name': CB_COOKIE_NAME,
66
       'services_url': CB_SERVICES_URL,
67
       'menu_url': CB_MENU_URL,
68
       'height': str(CB_HEIGHT),
69
       'bg_color': CB_BGCOLOR}
70

  
71
    CB_CODE = mark_safe(CB_CODE)
72

  
73
    return {
74
        'CLOUDBAR_ACTIVE': CB_ACTIVE,
75
        'CLOUDBAR_LOCATION': CB_LOCATION,
76
        'CLOUDBAR_COOKIE_NAME': CB_COOKIE_NAME,
77
        'CLOUDBAR_SERVICES_URL': CB_SERVICES_URL,
78
        'CLOUDBAR_MENU_URL': CB_MENU_URL,
79
        'CLOUDBAR_CODE': CB_CODE
80
    }
b/snf-cyclades-app/synnefo/app_settings/__init__.py
11 11
]
12 12

  
13 13
synnefo_web_middleware = []
14
synnefo_web_context_processors = ['synnefo.lib.context_processors.cloudbar']
14
synnefo_web_context_processors = \
15
    ['synnefo.webproject.context_processors.cloudbar']
15 16

  
16 17
synnefo_static_files = {
17 18
    'synnefo.ui': 'ui/static',
b/snf-webproject/synnefo/webproject/context_processors.py
1
from django.utils.safestring import mark_safe
2
from django.conf import settings
3

  
4

  
5
def cloudbar(request):
6
    """
7
    Django context processor that applies all cloudbar settings in response
8
    context plus a ready to use pre rendered script html tag containing valid
9
    javascript code for cloudbar to display.
10

  
11
    To use it add ``synnefo.webproject.context_processors.cloudbar`` in your
12
    project's ``TEMPLATE_CONTEXT_PROCESSORS setting`` (snf-webproject already
13
    does).
14

  
15
    Then in your base html template::
16

  
17
        <html>
18
        ....
19
        <head>
20
        ...
21
        {% if CLOUDBAR_ACTIVE %}
22
            {{ CLOUDBAR_CODE }}
23
        {% endif %}
24
        </head>
25
        <body>
26
        ....
27
        </body>
28
        </html>
29

  
30

  
31
    """
32

  
33
    CB_ACTIVE = getattr(settings, 'CLOUDBAR_ACTIVE', True)
34
    CB_LOCATION = getattr(settings, 'CLOUDBAR_LOCATION')
35
    CB_COOKIE_NAME = getattr(settings, 'CLOUDBAR_COOKIE_NAME',
36
            'okeanos_account')
37
    CB_SERVICES_URL = getattr(settings, 'CLOUDBAR_SERVICES_URL')
38
    CB_MENU_URL = getattr(settings, 'CLOUDBAR_MENU_URL')
39
    CB_HEIGHT = getattr(settings, 'CLOUDBAR_HEIGHT',
40
            '35')
41
    CB_BGCOLOR = getattr(settings, 'CLOUDBAR_BACKGROUND_COLOR',
42
            '#000000')
43

  
44
    CB_CODE = """
45
    <script type="text/javascript">
46
        var CLOUDBAR_LOCATION = "%(location)s";
47
        var CLOUDBAR_COOKIE_NAME = "%(cookie_name)s";
48
        var GET_SERVICES_URL = "%(services_url)s";
49
        var GET_MENU_URL = "%(menu_url)s";
50
        var CLOUDBAR_HEIGHT = '%(height)s';
51

  
52
        $(document).ready(function(){
53
            $.getScript(CLOUDBAR_LOCATION + 'cloudbar.js');
54
        });
55

  
56
    </script>
57
    <style>
58
        body {
59
            border-top: %(height)spx solid %(bg_color)s;
60
        }
61
        body .cloudbar {
62
            height: %(height)spx;
63
        }
64
    </style>
65
""" % {'location': CB_LOCATION,
66
       'cookie_name': CB_COOKIE_NAME,
67
       'services_url': CB_SERVICES_URL,
68
       'menu_url': CB_MENU_URL,
69
       'height': str(CB_HEIGHT),
70
       'bg_color': CB_BGCOLOR}
71

  
72
    CB_CODE = mark_safe(CB_CODE)
73

  
74
    return {
75
        'CLOUDBAR_ACTIVE': CB_ACTIVE,
76
        'CLOUDBAR_LOCATION': CB_LOCATION,
77
        'CLOUDBAR_COOKIE_NAME': CB_COOKIE_NAME,
78
        'CLOUDBAR_SERVICES_URL': CB_SERVICES_URL,
79
        'CLOUDBAR_MENU_URL': CB_MENU_URL,
80
        'CLOUDBAR_CODE': CB_CODE
81
    }

Also available in: Unified diff