Created
April 11, 2011 19:33
-
-
Save nwalker/914142 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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