diff --git a/ChangeLog b/ChangeLog index 3d8f5f54bd..22a14993ec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2015-07-21 Raymond Penners + * Template context processors are no longer used. + * The Facebook Graph API fields (/me/?fields=...) can now be configured using the provider `FIELDS` setting. diff --git a/allauth/account/context_processors.py b/allauth/account/context_processors.py deleted file mode 100644 index c59c4091d9..0000000000 --- a/allauth/account/context_processors.py +++ /dev/null @@ -1,6 +0,0 @@ -def account(request): - # We used to have this due to the now removed - # settings.CONTACT_EMAIL. Let's see if we need a context processor - # in the future, otherwise, deprecate this context processor - # completely. - return { } 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 8158220f11..8d121fac7f 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -8,6 +8,12 @@ From 0.21.0 - The default Facebook Graph API version is now v2.4. +- Template context processors are no longer used. 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 e2e0b412f5..f5a8efe847 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -16,10 +16,6 @@ settings.py (Important - Please note 'django.contrib.sites' is required as INSTA # Required by `allauth` template tags 'django.core.context_processors.request', ... - # `allauth` specific context processors - 'allauth.account.context_processors.account', - 'allauth.socialaccount.context_processors.socialaccount', - ... ) # If you are running Django 1.8+, specify the context processors @@ -35,10 +31,6 @@ settings.py (Important - Please note 'django.contrib.sites' is required as INSTA # `allauth` needs this from django 'django.template.context_processors.request', - - # `allauth` specific context processors - 'allauth.account.context_processors.account', - '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 d9974a7ebe..62349babf1 100644 --- a/example/example/settings.py +++ b/example/example/settings.py @@ -117,9 +117,6 @@ "django.core.context_processors.static", "django.core.context_processors.request", "django.contrib.messages.context_processors.messages", - - "allauth.account.context_processors.account", - "allauth.socialaccount.context_processors.socialaccount", ) TEMPLATE_DIRS = ( diff --git a/test_settings.py b/test_settings.py index 6f28d840be..e983f78d4b 100644 --- a/test_settings.py +++ b/test_settings.py @@ -29,9 +29,7 @@ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', - 'django.contrib.messages.context_processors.messages', - 'allauth.account.context_processors.account', - 'allauth.socialaccount.context_processors.socialaccount', + 'django.contrib.messages.context_processors.messages' ], }, }, @@ -45,9 +43,6 @@ "django.core.context_processors.static", "django.core.context_processors.request", "django.contrib.messages.context_processors.messages", - - "allauth.account.context_processors.account", - "allauth.socialaccount.context_processors.socialaccount", ) MIDDLEWARE_CLASSES = (