1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
from django.apps import apps as django_apps
from django.core.exceptions import ImproperlyConfigured
from .app_settings import app_settings
try:
import importlib
except ImportError:
from django.utils import importlib
def import_attribute(path):
assert isinstance(path, str)
pkg, attr = path.rsplit(".", 1)
ret = getattr(importlib.import_module(pkg), attr)
return ret
def get_invite_form():
"""
Returns the form for sending an invite.
"""
return import_attribute(app_settings.INVITE_FORM)
def get_invitation_admin_add_form():
"""
Returns the form for creating a new invitation in admin.
"""
return import_attribute(app_settings.ADMIN_ADD_FORM)
def get_invitation_admin_change_form():
"""
Returns the form for changing invitations in admin.
"""
return import_attribute(app_settings.ADMIN_CHANGE_FORM)
def get_invitation_model():
"""
Returns the Invitation model that is active in this project.
"""
path = app_settings.INVITATION_MODEL
try:
return django_apps.get_model(path)
except ValueError:
raise ImproperlyConfigured("path must be of the form 'app_label.model_name'")
except LookupError:
raise ImproperlyConfigured(
"path refers to model '%s' that\
has not been installed"
% app_settings.INVITATION_MODEL,
)
|