|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
from __future__ import unicode_literals |
|
3
|
|
|
""" |
|
4
|
|
|
Registration Supplement |
|
5
|
|
|
""" |
|
6
|
|
|
__author__ = 'Alisue <[email protected]>' |
|
7
|
|
|
__all__ = ('RegistrationSupplementBase', 'get_supplement_class') |
|
8
|
|
|
from django.core.exceptions import ImproperlyConfigured |
|
9
|
|
|
|
|
10
|
|
|
from registration.compat import import_module |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
def get_supplement_class(path=None): |
|
14
|
|
|
""" |
|
15
|
|
|
Return an instance of a registration supplement, given the dotted |
|
16
|
|
|
Python import path (as a string) to the supplement class. |
|
17
|
|
|
|
|
18
|
|
|
If the addition cannot be located (e.g., because no such module |
|
19
|
|
|
exists, or because the module does not contain a class of the |
|
20
|
|
|
appropriate name), ``django.core.exceptions.ImproperlyConfigured`` |
|
21
|
|
|
is raised. |
|
22
|
|
|
|
|
23
|
|
|
""" |
|
24
|
|
|
from registration.conf import settings |
|
25
|
|
|
path = path or settings.REGISTRATION_SUPPLEMENT_CLASS |
|
26
|
|
|
if not path: |
|
27
|
|
|
return None |
|
28
|
|
|
i = path.rfind('.') |
|
29
|
|
|
module, attr = path[:i], path[i+1:] |
|
30
|
|
|
try: |
|
31
|
|
|
mod = import_module(module) |
|
32
|
|
|
except ImportError as e: |
|
33
|
|
|
raise ImproperlyConfigured( |
|
34
|
|
|
'Error loading registration addition %s: "%s"' % (module, e)) |
|
35
|
|
|
try: |
|
36
|
|
|
cls = getattr(mod, attr) |
|
37
|
|
|
except AttributeError: |
|
38
|
|
|
raise ImproperlyConfigured(( |
|
39
|
|
|
'Module "%s" does not define a registration supplement named ' |
|
40
|
|
|
'"%s"') % (module, attr)) |
|
41
|
|
|
from registration.supplements.base import RegistrationSupplementBase |
|
42
|
|
|
if cls and not issubclass(cls, RegistrationSupplementBase): |
|
43
|
|
|
raise ImproperlyConfigured(( |
|
44
|
|
|
'Registration supplement class "%s" must be a subclass of ' |
|
45
|
|
|
'``registration.supplements.RegistrationSupplementBase``') % path) |
|
46
|
|
|
return cls |
|
47
|
|
|
|