Skip to content

Commit

Permalink
Merge 208b0dd into 9c31b65
Browse files Browse the repository at this point in the history
  • Loading branch information
velis74 committed Aug 14, 2018
2 parents 9c31b65 + 208b0dd commit b4594dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
15 changes: 14 additions & 1 deletion allauth/socialaccount/providers/__init__.py
Expand Up @@ -11,10 +11,23 @@ def __init__(self):
self.loaded = False

def get_list(self, request=None):
from django.contrib.sites.models import Site
from .openid.provider import OpenIDProvider
from django.core.exceptions import ImproperlyConfigured

self.load()

try:
site = Site.objects.get_current(request)
ids = [sa.provider for sa in site.socialapp_set.all()]
# OpenID doesn't require social apps so add it regardless
ids.append(OpenIDProvider.id)
except ImproperlyConfigured:
ids = self.provider_map.keys()
return [
provider_cls(request)
for provider_cls in self.provider_map.values()]
for provider_cls in self.provider_map.values()
if provider_cls.id in ids]

def register(self, cls):
self.provider_map[cls.id] = cls
Expand Down
7 changes: 4 additions & 3 deletions allauth/socialaccount/templatetags/socialaccount.py
Expand Up @@ -81,8 +81,8 @@ def get_social_accounts(user):
return accounts


@register.simple_tag
def get_providers():
@register.simple_tag(takes_context=True)
def get_providers(context):
"""
Returns a list of social authentication providers.
Expand All @@ -91,4 +91,5 @@ def get_providers():
Then within the template context, `socialaccount_providers` will hold
a list of social providers configured for the current site.
"""
return providers.registry.get_list()
request = context['request']
return providers.registry.get_list(request)

0 comments on commit b4594dc

Please sign in to comment.