Skip to content

Instantly share code, notes, and snippets.

@nwalker
Created April 11, 2011 19:33
Show Gist options
  • Save nwalker/914142 to your computer and use it in GitHub Desktop.
Save nwalker/914142 to your computer and use it in GitHub Desktop.
# import sources from where check for auth backends
SOCIAL_AUTH_IMPORT_SOURCES = (
'social_auth.backends',
'social_auth.backends.contrib',
) + getattr(settings, 'SOCIAL_AUTH_IMPORT_BACKENDS', ())
def get_backends():
backends = {}
for mod_name in SOCIAL_AUTH_IMPORT_SOURCES:
try:
mod = import_module(mod_name)
except ImportError:
continue
for directory, subdir, files in walk(mod.__path__[0]):
for name in filter(lambda name: name.endswith('.py'), files):
try:
name = basename(name).replace('.py', '')
sub = import_module(mod_name + '.' + name)
# register only enabled backends
backends.update(((key, val)
for key, val in sub.BACKENDS.items()
if val.enabled()))
except (ImportError, AttributeError):
pass
return backends
# load backends from defined modules
BACKENDS = get_backends()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment