diff options
Diffstat (limited to 'gstudio/url_shortener/__init__.py')
-rw-r--r-- | gstudio/url_shortener/__init__.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/gstudio/url_shortener/__init__.py b/gstudio/url_shortener/__init__.py new file mode 100644 index 00000000..d334d892 --- /dev/null +++ b/gstudio/url_shortener/__init__.py @@ -0,0 +1,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 |