1. jesumer Escat
  2. django-registration

Commits

James Bennett  committed 51876cf

Add utility function for retrieving the active registration backend.

  • Participants
  • Parent commits aa40d44
  • Branches default

Comments (0)

Files changed (1)

File registration/__init__.py

View file
  • Ignore whitespace
+from django.conf import settings
+from django.core.exceptions import ImproperlyConfigured
+from django.utils.importlib import import_module
+
+def get_backend():
+    """
+    Return an instance of the registration backend for use on this
+    site, as determined by the ``REGISTRATION_BACKEND`` setting. Raise
+    ``django.core.exceptions.ImproperlyConfigured`` if the specified
+    backend cannot be located.
+    
+    """
+    i = settings.REGISTRATION_BACKEND.rfind('.')
+    module, attr = settings.REGISTRATION_BACKEND[:i], settings.REGISTRATION_BACKEND[i+1:]
+    try:
+        mod = import_module(module)
+    except ImportError, e:
+        raise ImproperlyConfigured('Error loading registration backend %s: "%s"' % (module, e))
+    try:
+        backend_class = getattr(mod, attr)
+    except AttributeError:
+        raise ImproperlyConfigured('Module "%s" does not define a registration backend named "%s"' % (module, attr))
+    return backend_class()