blob: d334d892d5de1b751ac03a96872fee7e6377172b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
"""Url shortener for Gstudio"""
import warnings
from django.utils.importlib import import_module
from django.core.exceptions import ImproperlyConfigured
from gstudio.settings import URL_SHORTENER_BACKEND
from gstudio.url_shortener.backends.default import backend as default_backend
def get_url_shortener():
"""Return the selected url shortener backend"""
try:
backend_module = import_module(URL_SHORTENER_BACKEND)
backend = getattr(backend_module, 'backend')
except (ImportError, AttributeError):
warnings.warn('%s backend cannot be imported' % URL_SHORTENER_BACKEND,
RuntimeWarning)
backend = default_backend
except ImproperlyConfigured, e:
warnings.warn(str(e), RuntimeWarning)
backend = default_backend
return backend
|