Skip to content

Commit 634f4fe

Browse files
committed
Merge remote-tracking branch 'refs/remotes/julen/issue/949-rm-ctx-processor'
2 parents b8aeec8 + 7a5838b commit 634f4fe

File tree

12 files changed

+40
-64
lines changed

12 files changed

+40
-64
lines changed

ChangeLog

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
2015-07-21 Raymond Penners <[email protected]>
22

3+
* Template context processors are no longer used.
4+
35
* The Facebook Graph API fields (/me/?fields=...) can now be
46
configured using the provider `FIELDS` setting.
57

allauth/account/context_processors.py

-6
This file was deleted.

allauth/app_settings.py

-33
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,7 @@
1-
import django
21
from django.conf import settings
3-
from django.core.exceptions import ImproperlyConfigured
4-
from django import template
52

63
SOCIALACCOUNT_ENABLED = 'allauth.socialaccount' in settings.INSTALLED_APPS
74

8-
9-
def check_context_processors():
10-
allauth_ctx = 'allauth.socialaccount.context_processors.socialaccount'
11-
ctx_present = False
12-
13-
if django.VERSION < (1, 8,):
14-
setting = "settings.TEMPLATE_CONTEXT_PROCESSORS"
15-
if allauth_ctx in settings.TEMPLATE_CONTEXT_PROCESSORS:
16-
ctx_present = True
17-
else:
18-
for name, engine in template.engines.templates.items():
19-
if allauth_ctx in engine.get('OPTIONS', {})\
20-
.get('context_processors', []):
21-
ctx_present = True
22-
else:
23-
setting = "settings.TEMPLATES['{}']['OPTIONS']['context_processors']"
24-
setting = setting.format(name)
25-
26-
if not ctx_present:
27-
excmsg = ("socialaccount context processor "
28-
"not found in {}. "
29-
"See settings.py instructions here: "
30-
"http://django-allauth.readthedocs.org/en/latest/installation.html")
31-
raise ImproperlyConfigured(excmsg.format(setting))
32-
33-
34-
if SOCIALACCOUNT_ENABLED:
35-
check_context_processors()
36-
37-
385
LOGIN_REDIRECT_URL = getattr(settings, 'LOGIN_REDIRECT_URL', '/')
396

407
USER_MODEL = getattr(settings, 'AUTH_USER_MODEL', 'auth.User')

allauth/socialaccount/context_processors.py

-5
This file was deleted.

allauth/socialaccount/templatetags/socialaccount.py

+13
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,16 @@ def get_social_accounts(user):
7878
providers = accounts.setdefault(account.provider, [])
7979
providers.append(account)
8080
return accounts
81+
82+
83+
@register.assignment_tag
84+
def get_providers():
85+
"""
86+
Returns a list of social authentication providers.
87+
88+
Usage: `{% get_providers as socialaccount_providers %}`.
89+
90+
Then within the template context, `socialaccount_providers` will hold
91+
a list of social providers configured for the current site.
92+
"""
93+
return providers.registry.get_list()

allauth/templates/account/login.html

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
{% extends "account/base.html" %}
22

33
{% load i18n %}
4-
{% load account %}
4+
{% load account socialaccount %}
55

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

88
{% block content %}
99

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

12-
{% if socialaccount.providers %}
12+
{% get_providers as socialaccount_providers %}
13+
14+
{% if socialaccount_providers %}
1315
<p>{% blocktrans with site.name as site_name %}Please sign in with one
1416
of your existing third party accounts. Or, <a href="{{ signup_url }}">sign up</a>
1517
for a {{ site_name }} account and sign in below:{% endblocktrans %}</p>

allauth/templates/socialaccount/snippets/provider_list.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{% load socialaccount %}
22

3-
{% for provider in socialaccount.providers %}
3+
{% get_providers as socialaccount_providers %}
4+
5+
{% for provider in socialaccount_providers %}
46
{% if provider.id == "openid" %}
57
{% for brand in provider.get_brands %}
68
<li>

docs/changelog.rst

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ From 0.21.0
88

99
- The default Facebook Graph API version is now v2.4.
1010

11+
- Template context processors are no longer used. The context
12+
processor for ``allauth.account`` was already empty, and the context
13+
processor for ``allauth.socialaccount`` has been converted into the
14+
:doc:`{% get_providers %} <templates>` template tag.
15+
16+
1117
From 0.20.0
1218
***********
1319

docs/installation.rst

-8
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ settings.py (Important - Please note 'django.contrib.sites' is required as INSTA
1616
# Required by `allauth` template tags
1717
'django.core.context_processors.request',
1818
...
19-
# `allauth` specific context processors
20-
'allauth.account.context_processors.account',
21-
'allauth.socialaccount.context_processors.socialaccount',
22-
...
2319
)
2420

2521
# 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
3531

3632
# `allauth` needs this from django
3733
'django.template.context_processors.request',
38-
39-
# `allauth` specific context processors
40-
'allauth.account.context_processors.account',
41-
'allauth.socialaccount.context_processors.socialaccount',
4234
],
4335
},
4436
},

docs/templates.rst

+11
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,14 @@ Then::
7070
{{accounts.twitter}} -- a list of connected Twitter accounts
7171
{{accounts.twitter.0}} -- the first Twitter account
7272
{% if accounts %} -- if there is at least one social account
73+
74+
75+
Finally, social authentication providers configured for the current site
76+
can be retrieved via::
77+
78+
{% get_providers as socialaccount_providers %}
79+
80+
Which will populate the ``socialaccount_providers`` variable in the
81+
template context with a list of configured social authentication
82+
providers. This supersedes the context processor used in version 0.21 and
83+
below.

example/example/settings.py

-3
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,6 @@
117117
"django.core.context_processors.static",
118118
"django.core.context_processors.request",
119119
"django.contrib.messages.context_processors.messages",
120-
121-
"allauth.account.context_processors.account",
122-
"allauth.socialaccount.context_processors.socialaccount",
123120
)
124121

125122
TEMPLATE_DIRS = (

test_settings.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@
2929
'django.template.context_processors.debug',
3030
'django.template.context_processors.request',
3131
'django.contrib.auth.context_processors.auth',
32-
'django.contrib.messages.context_processors.messages',
33-
'allauth.account.context_processors.account',
34-
'allauth.socialaccount.context_processors.socialaccount',
32+
'django.contrib.messages.context_processors.messages'
3533
],
3634
},
3735
},
@@ -45,9 +43,6 @@
4543
"django.core.context_processors.static",
4644
"django.core.context_processors.request",
4745
"django.contrib.messages.context_processors.messages",
48-
49-
"allauth.account.context_processors.account",
50-
"allauth.socialaccount.context_processors.socialaccount",
5146
)
5247

5348
MIDDLEWARE_CLASSES = (

0 commit comments

Comments
 (0)