Statistics
| Branch: | Tag: | Revision:

root / snf-astakos-app / astakos / im / context_processors.py @ 4bdd7e3d

History | View | Annotate | Download (3.9 kB)

1 0905ccd2 Sofia Papagiannaki
# Copyright 2011 GRNET S.A. All rights reserved.
2 13858d75 Kostas Papadimitriou
#
3 0905ccd2 Sofia Papagiannaki
# Redistribution and use in source and binary forms, with or
4 0905ccd2 Sofia Papagiannaki
# without modification, are permitted provided that the following
5 0905ccd2 Sofia Papagiannaki
# conditions are met:
6 13858d75 Kostas Papadimitriou
#
7 0905ccd2 Sofia Papagiannaki
#   1. Redistributions of source code must retain the above
8 0905ccd2 Sofia Papagiannaki
#      copyright notice, this list of conditions and the following
9 0905ccd2 Sofia Papagiannaki
#      disclaimer.
10 13858d75 Kostas Papadimitriou
#
11 0905ccd2 Sofia Papagiannaki
#   2. Redistributions in binary form must reproduce the above
12 0905ccd2 Sofia Papagiannaki
#      copyright notice, this list of conditions and the following
13 0905ccd2 Sofia Papagiannaki
#      disclaimer in the documentation and/or other materials
14 0905ccd2 Sofia Papagiannaki
#      provided with the distribution.
15 13858d75 Kostas Papadimitriou
#
16 0905ccd2 Sofia Papagiannaki
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 0905ccd2 Sofia Papagiannaki
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 0905ccd2 Sofia Papagiannaki
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 0905ccd2 Sofia Papagiannaki
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 0905ccd2 Sofia Papagiannaki
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 0905ccd2 Sofia Papagiannaki
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 0905ccd2 Sofia Papagiannaki
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 0905ccd2 Sofia Papagiannaki
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 0905ccd2 Sofia Papagiannaki
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 0905ccd2 Sofia Papagiannaki
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 0905ccd2 Sofia Papagiannaki
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 0905ccd2 Sofia Papagiannaki
# POSSIBILITY OF SUCH DAMAGE.
28 13858d75 Kostas Papadimitriou
#
29 0905ccd2 Sofia Papagiannaki
# The views and conclusions contained in the software and
30 0905ccd2 Sofia Papagiannaki
# documentation are those of the authors and should not be
31 0905ccd2 Sofia Papagiannaki
# interpreted as representing official policies, either expressed
32 0905ccd2 Sofia Papagiannaki
# or implied, of GRNET S.A.
33 0905ccd2 Sofia Papagiannaki
34 c0b26605 Sofia Papagiannaki
from astakos.im.settings import (
35 c0b26605 Sofia Papagiannaki
    IM_MODULES, INVITATIONS_ENABLED, IM_STATIC_URL,
36 c0b26605 Sofia Papagiannaki
    LOGIN_MESSAGES, SIGNUP_MESSAGES, PROFILE_MESSAGES,
37 5ce3ce4f Sofia Papagiannaki
    GLOBAL_MESSAGES, PROFILE_EXTRA_LINKS
38 c0b26605 Sofia Papagiannaki
)
39 14c5be5a Sofia Papagiannaki
from astakos.im.api import get_menu
40 0a569195 Sofia Papagiannaki
from astakos.im.util import get_query
41 0f4fa26d Sofia Papagiannaki
from astakos.im.models import GroupKind
42 d2633501 Kostas Papadimitriou
from astakos.im.auth_providers import PROVIDERS as AUTH_PROVIDERS
43 f534fb96 Sofia Papagiannaki
44 f534fb96 Sofia Papagiannaki
from django.utils import simplejson as json
45 0905ccd2 Sofia Papagiannaki
46 5ce3ce4f Sofia Papagiannaki
47 0905ccd2 Sofia Papagiannaki
def im_modules(request):
48 92defad4 Sofia Papagiannaki
    return {'im_modules': IM_MODULES}
49 0905ccd2 Sofia Papagiannaki
50 d2633501 Kostas Papadimitriou
def auth_providers(request):
51 6012535a Kostas Papadimitriou
    active_auth_providers = []
52 6012535a Kostas Papadimitriou
    for module in IM_MODULES:
53 08621fa5 Kostas Papadimitriou
        provider = AUTH_PROVIDERS.get(module, None)
54 6012535a Kostas Papadimitriou
        if provider:
55 08621fa5 Kostas Papadimitriou
            active_auth_providers.append(provider())
56 6012535a Kostas Papadimitriou
57 6012535a Kostas Papadimitriou
    return {'auth_providers': active_auth_providers,
58 6012535a Kostas Papadimitriou
            'master_auth_provider': active_auth_providers[0]}
59 d2633501 Kostas Papadimitriou
60 0905ccd2 Sofia Papagiannaki
def next(request):
61 5ce3ce4f Sofia Papagiannaki
    return {'next': get_query(request).get('next', '')}
62 5ce3ce4f Sofia Papagiannaki
63 0905ccd2 Sofia Papagiannaki
64 0905ccd2 Sofia Papagiannaki
def code(request):
65 5ce3ce4f Sofia Papagiannaki
    return {'code': request.GET.get('code', '')}
66 5ce3ce4f Sofia Papagiannaki
67 890b0eaf Sofia Papagiannaki
68 890b0eaf Sofia Papagiannaki
def invitations(request):
69 5ce3ce4f Sofia Papagiannaki
    return {'invitations_enabled': INVITATIONS_ENABLED}
70 5ce3ce4f Sofia Papagiannaki
71 13858d75 Kostas Papadimitriou
72 13858d75 Kostas Papadimitriou
def media(request):
73 5ce3ce4f Sofia Papagiannaki
    return {'IM_STATIC_URL': IM_STATIC_URL}
74 5ce3ce4f Sofia Papagiannaki
75 13858d75 Kostas Papadimitriou
76 25d9d4d0 Sofia Papagiannaki
def custom_messages(request):
77 60e78c99 Kostas Papadimitriou
    global GLOBAL_MESSAGES, SIGNUP_MESSAGES, LOGIN_MESSAGES, PROFILE_MESSAGES
78 60e78c99 Kostas Papadimitriou
79 60e78c99 Kostas Papadimitriou
    # keep backwards compatibility with dict settings
80 60e78c99 Kostas Papadimitriou
    if type(GLOBAL_MESSAGES) == dict:
81 60e78c99 Kostas Papadimitriou
        GLOBAL_MESSAGES = GLOBAL_MESSAGES.items()
82 60e78c99 Kostas Papadimitriou
    if type(SIGNUP_MESSAGES) == dict:
83 60e78c99 Kostas Papadimitriou
        SIGNUP_MESSAGES = SIGNUP_MESSAGES.items()
84 60e78c99 Kostas Papadimitriou
    if type(LOGIN_MESSAGES) == dict:
85 60e78c99 Kostas Papadimitriou
        LOGIN_MESSAGES = LOGIN_MESSAGES.items()
86 60e78c99 Kostas Papadimitriou
    if type(PROFILE_MESSAGES) == dict:
87 60e78c99 Kostas Papadimitriou
        PROFILE_MESSAGES = PROFILE_MESSAGES.items()
88 60e78c99 Kostas Papadimitriou
89 9a06d96f Olga Brani
    EXTRA_MESSAGES_SET = bool(GLOBAL_MESSAGES or SIGNUP_MESSAGES or
90 9a06d96f Olga Brani
                              LOGIN_MESSAGES or PROFILE_MESSAGES)
91 60e78c99 Kostas Papadimitriou
92 25d9d4d0 Sofia Papagiannaki
    return {
93 5ce3ce4f Sofia Papagiannaki
        'GLOBAL_MESSAGES': GLOBAL_MESSAGES,
94 5ce3ce4f Sofia Papagiannaki
        'SIGNUP_MESSAGES': SIGNUP_MESSAGES,
95 5ce3ce4f Sofia Papagiannaki
        'LOGIN_MESSAGES': LOGIN_MESSAGES,
96 5ce3ce4f Sofia Papagiannaki
        'PROFILE_MESSAGES': PROFILE_MESSAGES,
97 5ce3ce4f Sofia Papagiannaki
        'PROFILE_EXTRA_LINKS': PROFILE_EXTRA_LINKS,
98 5ce3ce4f Sofia Papagiannaki
        'EXTRA_MESSAGES_SET': EXTRA_MESSAGES_SET
99 5ce3ce4f Sofia Papagiannaki
    }
100 5ce3ce4f Sofia Papagiannaki
101 25d9d4d0 Sofia Papagiannaki
102 f534fb96 Sofia Papagiannaki
def menu(request):
103 7ee456f7 root
    try:
104 a88d9ec1 Sofia Papagiannaki
        resp = get_menu(request, True, False)
105 7ee456f7 root
        menu_items = json.loads(resp.content)[1:]
106 7ee456f7 root
    except Exception, e:
107 7ee456f7 root
        return {}
108 7ee456f7 root
    else:
109 5ce3ce4f Sofia Papagiannaki
        return {'menu': menu_items}
110 5ce3ce4f Sofia Papagiannaki
111 0f4fa26d Sofia Papagiannaki
112 0f4fa26d Sofia Papagiannaki
def group_kinds(request):
113 5ce3ce4f Sofia Papagiannaki
    return {'group_kinds': GroupKind.objects.exclude(
114 c9015cf6 Sofia Papagiannaki
        name='default').values_list('name', flat=True)}