Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/julen/issue/949-rm-ctx-pro…
Browse files Browse the repository at this point in the history
…cessor'
  • Loading branch information
pennersr committed Jul 21, 2015
2 parents b8aeec8 + 7a5838b commit 634f4fe
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 64 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
2015-07-21 Raymond Penners <raymond.penners@intenct.nl>

* Template context processors are no longer used.

* The Facebook Graph API fields (/me/?fields=...) can now be
configured using the provider `FIELDS` setting.

Expand Down
6 changes: 0 additions & 6 deletions allauth/account/context_processors.py

This file was deleted.

33 changes: 0 additions & 33 deletions allauth/app_settings.py
Original file line number Diff line number Diff line change
@@ -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')
5 changes: 0 additions & 5 deletions allauth/socialaccount/context_processors.py

This file was deleted.

13 changes: 13 additions & 0 deletions allauth/socialaccount/templatetags/socialaccount.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
6 changes: 4 additions & 2 deletions allauth/templates/account/login.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{% extends "account/base.html" %}

{% load i18n %}
{% load account %}
{% load account socialaccount %}

{% block head_title %}{% trans "Sign In" %}{% endblock %}

{% block content %}

<h1>{% trans "Sign In" %}</h1>

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

{% if socialaccount_providers %}
<p>{% blocktrans with site.name as site_name %}Please sign in with one
of your existing third party accounts. Or, <a href="{{ signup_url }}">sign up</a>
for a {{ site_name }} account and sign in below:{% endblocktrans %}</p>
Expand Down
4 changes: 3 additions & 1 deletion allauth/templates/socialaccount/snippets/provider_list.html
Original file line number Diff line number Diff line change
@@ -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 %}
<li>
Expand Down
6 changes: 6 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 %} <templates>` template tag.


From 0.20.0
***********

Expand Down
8 changes: 0 additions & 8 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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',
],
},
},
Expand Down
11 changes: 11 additions & 0 deletions docs/templates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
3 changes: 0 additions & 3 deletions example/example/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
7 changes: 1 addition & 6 deletions test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
],
},
},
Expand All @@ -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 = (
Expand Down

0 comments on commit 634f4fe

Please sign in to comment.