diff --git a/allauth/app_settings.py b/allauth/app_settings.py index 6084bc6744..eb631485ef 100644 --- a/allauth/app_settings.py +++ b/allauth/app_settings.py @@ -1,40 +1,7 @@ -import django from django.conf import settings -from django.core.exceptions import ImproperlyConfigured -from django import template SOCIALACCOUNT_ENABLED = 'allauth.socialaccount' in settings.INSTALLED_APPS - -def check_context_processors(): - allauth_ctx = 'allauth.socialaccount.context_processors.socialaccount' - ctx_present = False - - if django.VERSION < (1, 8,): - setting = "settings.TEMPLATE_CONTEXT_PROCESSORS" - if allauth_ctx in settings.TEMPLATE_CONTEXT_PROCESSORS: - ctx_present = True - else: - for name, engine in template.engines.templates.items(): - if allauth_ctx in engine.get('OPTIONS', {})\ - .get('context_processors', []): - ctx_present = True - else: - setting = "settings.TEMPLATES['{}']['OPTIONS']['context_processors']" - setting = setting.format(name) - - if not ctx_present: - excmsg = ("socialaccount context processor " - "not found in {}. " - "See settings.py instructions here: " - "http://django-allauth.readthedocs.org/en/latest/installation.html") - raise ImproperlyConfigured(excmsg.format(setting)) - - -if SOCIALACCOUNT_ENABLED: - check_context_processors() - - LOGIN_REDIRECT_URL = getattr(settings, 'LOGIN_REDIRECT_URL', '/') USER_MODEL = getattr(settings, 'AUTH_USER_MODEL', 'auth.User') diff --git a/allauth/socialaccount/context_processors.py b/allauth/socialaccount/context_processors.py deleted file mode 100644 index 55d1182f31..0000000000 --- a/allauth/socialaccount/context_processors.py +++ /dev/null @@ -1,5 +0,0 @@ -from . import providers - -def socialaccount(request): - ctx = { 'providers': providers.registry.get_list() } - return dict(socialaccount=ctx) diff --git a/allauth/socialaccount/templatetags/socialaccount.py b/allauth/socialaccount/templatetags/socialaccount.py index 6b8c665b6a..b5de9da129 100644 --- a/allauth/socialaccount/templatetags/socialaccount.py +++ b/allauth/socialaccount/templatetags/socialaccount.py @@ -78,3 +78,16 @@ def get_social_accounts(user): providers = accounts.setdefault(account.provider, []) providers.append(account) return accounts + + +@register.assignment_tag +def get_providers(): + """ + Returns a list of social authentication providers. + + Usage: `{% get_providers as socialaccount_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() diff --git a/allauth/templates/account/login.html b/allauth/templates/account/login.html index 13d4e61754..17bc3a6a40 100644 --- a/allauth/templates/account/login.html +++ b/allauth/templates/account/login.html @@ -1,7 +1,7 @@ {% extends "account/base.html" %} {% load i18n %} -{% load account %} +{% load account socialaccount %} {% block head_title %}{% trans "Sign In" %}{% endblock %} @@ -9,7 +9,9 @@

{% trans "Sign In" %}

-{% if socialaccount.providers %} +{% get_providers as socialaccount_providers %} + +{% if socialaccount_providers %}

{% blocktrans with site.name as site_name %}Please sign in with one of your existing third party accounts. Or, sign up for a {{ site_name }} account and sign in below:{% endblocktrans %}

diff --git a/allauth/templates/socialaccount/snippets/provider_list.html b/allauth/templates/socialaccount/snippets/provider_list.html index f65d276fc6..a5e3b02702 100644 --- a/allauth/templates/socialaccount/snippets/provider_list.html +++ b/allauth/templates/socialaccount/snippets/provider_list.html @@ -1,6 +1,8 @@ {% load socialaccount %} -{% for provider in socialaccount.providers %} +{% get_providers as socialaccount_providers %} + +{% for provider in socialaccount_providers %} {% if provider.id == "openid" %} {% for brand in provider.get_brands %}
  • diff --git a/docs/changelog.rst b/docs/changelog.rst index 86689886bb..5dc8ea1674 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -4,6 +4,15 @@ Changelog This chapter contains notes on upgrading. +From 0.21.0 +*********** + +- Allauth doesn't enforce template context processors anymore. The context + processor for ``allauth.account`` was already empty, and the context + processor for ``allauth.socialaccount`` has been converted into the + :doc:`{% get_providers %} ` template tag. + + From 0.20.0 *********** diff --git a/docs/installation.rst b/docs/installation.rst index 562186333f..3ae99a0434 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -16,9 +16,6 @@ settings.py:: # Required by `allauth` template tags 'django.core.context_processors.request', ... - # `allauth` specific context processors - 'allauth.socialaccount.context_processors.socialaccount', - ... ) # If you are running Django 1.8+, specify the context processors @@ -34,9 +31,6 @@ settings.py:: # `allauth` needs this from django 'django.template.context_processors.request', - - # `allauth` specific context processors - 'allauth.socialaccount.context_processors.socialaccount', ], }, }, diff --git a/docs/templates.rst b/docs/templates.rst index 82ed85a6b8..a1dec5d429 100644 --- a/docs/templates.rst +++ b/docs/templates.rst @@ -70,3 +70,14 @@ Then:: {{accounts.twitter}} -- a list of connected Twitter accounts {{accounts.twitter.0}} -- the first Twitter account {% if accounts %} -- if there is at least one social account + + +Finally, social authentication providers configured for the current site +can be retrieved via:: + + {% get_providers as socialaccount_providers %} + +Which will populate the ``socialaccount_providers`` variable in the +template context with a list of configured social authentication +providers. This supersedes the context processor used in version 0.21 and +below. diff --git a/example/example/settings.py b/example/example/settings.py index 81b1bb2282..62349babf1 100644 --- a/example/example/settings.py +++ b/example/example/settings.py @@ -117,8 +117,6 @@ "django.core.context_processors.static", "django.core.context_processors.request", "django.contrib.messages.context_processors.messages", - - "allauth.socialaccount.context_processors.socialaccount", ) TEMPLATE_DIRS = ( diff --git a/test_settings.py b/test_settings.py index 8de6ff9470..6af74b6d10 100644 --- a/test_settings.py +++ b/test_settings.py @@ -31,7 +31,6 @@ 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', 'django.core.context_processors.request', - 'allauth.socialaccount.context_processors.socialaccount', ], }, }, @@ -45,8 +44,6 @@ "django.core.context_processors.static", "django.core.context_processors.request", "django.contrib.messages.context_processors.messages", - - "allauth.socialaccount.context_processors.socialaccount", ) MIDDLEWARE_CLASSES = (