| 1 |
|
| 2 |
from importlib import import_module |
| 3 |
from typing import Optional |
| 4 |
from typing import Text |
| 5 |
|
| 6 |
from organizations.app_settings import ORGS_INVITATION_BACKEND |
| 7 |
from organizations.app_settings import ORGS_REGISTRATION_BACKEND |
| 8 |
from organizations.backends.defaults import BaseBackend |
| 9 |
|
| 10 |
|
| 11 |
def invitation_backend(backend=None, namespace=None): |
| 12 |
|
| 13 |
""" |
| 14 |
Returns a specified invitation backend |
| 15 |
|
| 16 |
Args: |
| 17 |
backend: dotted path to the invitation backend class |
| 18 |
namespace: URL namespace to use |
| 19 |
|
| 20 |
Returns: |
| 21 |
an instance of an InvitationBackend |
| 22 |
|
| 23 |
""" |
| 24 |
backend = backend or ORGS_INVITATION_BACKEND |
| 25 |
class_module, class_name = backend.rsplit(".", 1) |
| 26 |
mod = import_module(class_module) |
| 27 |
return getattr(mod, class_name)(namespace=namespace) |
| 28 |
|
| 29 |
|
| 30 |
def registration_backend(backend=None, namespace=None): |
| 31 |
|
| 32 |
""" |
| 33 |
Returns a specified registration backend |
| 34 |
|
| 35 |
Args: |
| 36 |
backend: dotted path to the registration backend class |
| 37 |
namespace: URL namespace to use |
| 38 |
|
| 39 |
Returns: |
| 40 |
an instance of an RegistrationBackend |
| 41 |
|
| 42 |
""" |
| 43 |
backend = backend or ORGS_REGISTRATION_BACKEND |
| 44 |
class_module, class_name = backend.rsplit(".", 1) |
| 45 |
mod = import_module(class_module) |
| 46 |
return getattr(mod, class_name)(namespace=namespace) |