Revision 081070a5 snf-astakos-app/astakos/im/auth_providers.py

b/snf-astakos-app/astakos/im/auth_providers.py
34 34

  
35 35
from django.core.urlresolvers import reverse
36 36
from django.utils.translation import ugettext as _
37
from django.utils.datastructures import SortedDict
37 38

  
38
from astakos.im import settings
39
from django.conf import settings
40
from astakos.im import settings as astakos_settings
39 41

  
40 42
import logging
41 43

  
42 44
logger = logging.getLogger(__name__)
43 45

  
44 46
# providers registry
45
PROVIDERS = {}
47
PROVIDERS = SortedDict()
48
_PROVIDERS = {}
46 49

  
47 50
class AuthProviderBase(type):
48 51

  
......
52 55
            type_id = dct.get('module')
53 56
            if type_id:
54 57
                include = True
55
            if type_id in settings.IM_MODULES:
58
            if type_id in astakos_settings.IM_MODULES:
56 59
                dct['module_enabled'] = True
57 60

  
58 61
        newcls = super(AuthProviderBase, cls).__new__(cls, name, bases, dct)
59 62
        if include:
60
            PROVIDERS[type_id] = newcls
63
            _PROVIDERS[type_id] = newcls
61 64
        return newcls
62 65

  
63 66

  
......
73 76
    def __init__(self, user=None):
74 77
        self.user = user
75 78

  
79
    def __getattr__(self, key):
80
        if not key.startswith('get_'):
81
            return super(AuthProvider, self).__getattr__(key)
82

  
83
        if key.endswith('_display') or key.endswith('template'):
84
            attr = key.replace('_display', '').replace('get_','')
85
            settings_attr = self.get_setting(attr.upper())
86
            if not settings_attr:
87
                return getattr(self, attr)
88
            return settings_attr
89
        else:
90
            return super(AuthProvider, self).__getattr__(key)
91

  
76 92
    def get_setting(self, name, default=None):
77
        attr = 'AUTH_PROVIDER_%s_%s' % (self.module.upper(), name.upper())
93
        attr = 'ASTAKOS_AUTH_PROVIDER_%s_%s' % (self.module.upper(), name.upper())
78 94
        return getattr(settings, attr, default)
79 95

  
80 96
    def is_available_for_login(self):
......
93 109
                                                   self.is_active())
94 110

  
95 111
    def is_active(self):
96
        return self.module in settings.IM_MODULES
112
        return self.module in astakos_settings.IM_MODULES
97 113

  
98 114

  
99 115
class LocalAuthProvider(AuthProvider):
100 116
    module = 'local'
101 117
    title = _('Local password')
102 118
    description = _('Create a local password for your account')
119
    create_prompt =  _('Create an account')
120
    add_prompt =  _('Create a local password for your account')
103 121

  
104 122

  
105 123
    @property
106 124
    def add_url(self):
107 125
        return reverse('password_change')
108 126

  
109
    add_description = _('Create a local password for your account')
110
    login_template = 'auth/local_login_form.html'
111
    add_template = 'auth/local_add_action.html'
112 127
    one_per_user = True
128

  
129
    login_template = 'im/auth/local_login_form.html'
130
    login_prompt_template = 'im/auth/local_login_prompt.html'
131
    signup_prompt_template = 'im/auth/local_signup_prompt.html'
113 132
    details_tpl = _('You can login to your account using your'
114 133
                    ' %(auth_backend)s password.')
115 134

  
......
123 142
    title = _('Academic credentials (Shibboleth)')
124 143
    description = _('Allows you to login to your account using your academic '
125 144
                    'credentials')
145
    add_prompt = _('Add academic credentials to your account.')
126 146

  
127 147
    @property
128 148
    def add_url(self):
129 149
        return reverse('astakos.im.target.shibboleth.login')
130 150

  
131
    add_description = _('Allows you to login to your account using your academic '
132
                    'credentials')
133
    login_template = 'auth/shibboleth_login_form.html'
134
    add_template = 'auth/shibboleth_add_action.html'
135
    details_tpl = _('You can login to your account using your'
136
                    ' shibboleth credentials. Shibboleth id: %(identifier)s')
151
    login_template = 'im/auth/shibboleth_login.html'
152
    login_prompt_template = 'im/auth/shibboleth_login_prompt.html'
137 153

  
138 154

  
139 155
def get_provider(id, user_obj=None, default=None):
......
142 158
    """
143 159
    return PROVIDERS.get(id, default)(user_obj)
144 160

  
161

  
162
for module in astakos_settings.IM_MODULES:
163
    if module in _PROVIDERS:
164
        PROVIDERS[module] = _PROVIDERS[module]
165

  

Also available in: Unified diff