Completed
Pull Request — master (#390)
by
unknown
24s
created

get_follow_model()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
from django.apps import apps as django_apps
2
from django.conf import settings as django_settings
3
from django.core.exceptions import ImproperlyConfigured
4
5
try:
6
    from actstream.signals import action
7
except ImportError:
8
    pass
9
10
__version__ = '0.7.0'
11
__author__ = 'Justin Quick <[email protected]>'
12
default_app_config = 'actstream.apps.ActstreamConfig'
13
14
15
def get_swappable_model(model_setting, default):
16
    model_lookup = getattr(django_settings, model_setting, default)
17
    try:
18
        return django_apps.get_model(model_lookup, require_ready=False)
19
    except ValueError:
20
        raise ImproperlyConfigured(
21
            "%s must be of the form 'app_label.model_name'" % model_setting
22
        )
23
    except LookupError:
24
        raise ImproperlyConfigured(
25
            "%s refers to model '%s' that has not been installed" % (model_setting, model_lookup)
26
        )
27
28
29
def get_follow_model():
30
    """Return the Follow model that is active."""
31
    return get_swappable_model('ACTSTREAM_FOLLOW_MODEL', 'actstream.Follow')
32
33
34
def get_action_model():
35
    """Return the Action model that is active."""
36
    return get_swappable_model('ACTSTREAM_ACTION_MODEL', 'actstream.Action')
37