-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathutils.py
More file actions
35 lines (28 loc) · 1.05 KB
/
utils.py
File metadata and controls
35 lines (28 loc) · 1.05 KB
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
from functools import cache
from django.apps import apps as django_apps
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.utils.module_loading import import_string
def get_site_model():
"""
Returns the configured site model or the default site model `feincms3_sites.Site`.
A custom site model can be configured in the settings like so
```
FEINCMS3_SITES_SITE_MODEL = 'myapp.CustomSite'
```
"""
model_name = settings.FEINCMS3_SITES_SITE_MODEL
try:
return django_apps.get_model(model_name, require_ready=False)
except ValueError as exc:
raise ImproperlyConfigured(
"FEINCMS3_SITES_SITE_MODEL must be of the form 'app_label.model_name'"
) from exc
except LookupError as exc:
raise ImproperlyConfigured(
"FEINCMS3_SITES_SITE_MODEL refers to model '%s' that has not been installed"
% model_name
) from exc
@cache
def import_callable(spec):
return spec if callable(spec) else import_string(spec)