context_processors.py 3.85 KB
Newer Older
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
1
# Copyright 2011 GRNET S.A. All rights reserved.
2
#
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
3
4
5
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
6
#
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
7
8
9
#   1. Redistributions of source code must retain the above
#      copyright notice, this list of conditions and the following
#      disclaimer.
10
#
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
11
12
13
14
#   2. Redistributions in binary form must reproduce the above
#      copyright notice, this list of conditions and the following
#      disclaimer in the documentation and/or other materials
#      provided with the distribution.
15
#
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
16
17
18
19
20
21
22
23
24
25
26
27
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
28
#
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
29
30
31
32
33
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.

34
35
36
from astakos.im.settings import (
    IM_MODULES, INVITATIONS_ENABLED, IM_STATIC_URL,
    LOGIN_MESSAGES, SIGNUP_MESSAGES, PROFILE_MESSAGES,
37
    GLOBAL_MESSAGES, PROFILE_EXTRA_LINKS
38
)
39
from astakos.im.api import get_menu
40
from astakos.im.util import get_query
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
41
from astakos.im.models import GroupKind
42
from astakos.im.auth_providers import PROVIDERS as AUTH_PROVIDERS
43
44

from django.utils import simplejson as json
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
45

46

Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
47
def im_modules(request):
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
48
    return {'im_modules': IM_MODULES}
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
49

50
def auth_providers(request):
51
52
    active_auth_providers = []
    for module in IM_MODULES:
53
        provider = AUTH_PROVIDERS.get(module, None)
54
        if provider:
55
            active_auth_providers.append(provider())
56
57
58

    return {'auth_providers': active_auth_providers,
            'master_auth_provider': active_auth_providers[0]}
59

Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
60
def next(request):
61
62
    return {'next': get_query(request).get('next', '')}

Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
63
64

def code(request):
65
66
    return {'code': request.GET.get('code', '')}

Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
67
68

def invitations(request):
69
70
    return {'invitations_enabled': INVITATIONS_ENABLED}

71
72

def media(request):
73
74
    return {'IM_STATIC_URL': IM_STATIC_URL}

75

Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
76
def custom_messages(request):
77
78
79
80
81
82
83
84
85
86
87
88
    global GLOBAL_MESSAGES, SIGNUP_MESSAGES, LOGIN_MESSAGES, PROFILE_MESSAGES

    # keep backwards compatibility with dict settings
    if type(GLOBAL_MESSAGES) == dict:
        GLOBAL_MESSAGES = GLOBAL_MESSAGES.items()
    if type(SIGNUP_MESSAGES) == dict:
        SIGNUP_MESSAGES = SIGNUP_MESSAGES.items()
    if type(LOGIN_MESSAGES) == dict:
        LOGIN_MESSAGES = LOGIN_MESSAGES.items()
    if type(PROFILE_MESSAGES) == dict:
        PROFILE_MESSAGES = PROFILE_MESSAGES.items()

Olga Brani's avatar
Olga Brani committed
89
90
    EXTRA_MESSAGES_SET = bool(GLOBAL_MESSAGES or SIGNUP_MESSAGES or
                              LOGIN_MESSAGES or PROFILE_MESSAGES)
91

Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
92
    return {
93
94
95
96
97
98
99
100
        'GLOBAL_MESSAGES': GLOBAL_MESSAGES,
        'SIGNUP_MESSAGES': SIGNUP_MESSAGES,
        'LOGIN_MESSAGES': LOGIN_MESSAGES,
        'PROFILE_MESSAGES': PROFILE_MESSAGES,
        'PROFILE_EXTRA_LINKS': PROFILE_EXTRA_LINKS,
        'EXTRA_MESSAGES_SET': EXTRA_MESSAGES_SET
    }

Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
101

102
def menu(request):
root's avatar
root committed
103
    try:
Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
104
        resp = get_menu(request, True, False)
root's avatar
root committed
105
106
107
108
        menu_items = json.loads(resp.content)[1:]
    except Exception, e:
        return {}
    else:
109
110
        return {'menu': menu_items}

Sofia Papagiannaki's avatar
Sofia Papagiannaki committed
111
112

def group_kinds(request):
113
    return {'group_kinds': GroupKind.objects.exclude(
114
        name='default').values_list('name', flat=True)}