Skip to content

Commit

Permalink
Merge 190379b into 62d814d
Browse files Browse the repository at this point in the history
  • Loading branch information
ERM committed Jan 29, 2016
2 parents 62d814d + 190379b commit aab22a2
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 30 deletions.
7 changes: 7 additions & 0 deletions allauth/account/app_settings.py
Expand Up @@ -237,6 +237,13 @@ def SESSION_REMEMBER(self):
"""
return self._setting('SESSION_REMEMBER', None)

@property
def TEMPLATE_EXTENSION(self):
"""
A string defining the template extension to use, defaults to `html`.
"""
return self._setting('TEMPLATE_EXTENSION', 'html')

@property
def FORMS(self):
return self._setting('FORMS', {})
Expand Down
20 changes: 11 additions & 9 deletions allauth/account/tests.py
Expand Up @@ -198,7 +198,8 @@ def test_password_reset_flow(self):
# Extract URL for `password_reset_from_key` view and access it
url = body[body.find('/password/reset/'):].split()[0]
resp = self.client.get(url)
self.assertTemplateUsed(resp, 'account/password_reset_from_key.html')
self.assertTemplateUsed(
resp, 'account/password_reset_from_key.%s' % app_settings.TEMPLATE_EXTENSION)
self.assertFalse('token_fail' in resp.context_data)

# Reset the password
Expand All @@ -217,13 +218,14 @@ def test_password_reset_flow(self):
resp = self.client.post(url,
{'password1': 'newpass123',
'password2': 'newpass123'})
self.assertTemplateUsed(resp, 'account/password_reset_from_key.html')
self.assertTemplateUsed(
resp, 'account/password_reset_from_key.%s' % app_settings.TEMPLATE_EXTENSION)
self.assertTrue(resp.context_data['token_fail'])

# Same should happen when accessing the page directly
response = self.client.get(url)
self.assertTemplateUsed(response,
'account/password_reset_from_key.html')
self.assertTemplateUsed(
response, 'account/password_reset_from_key.%s' % app_settings.TEMPLATE_EXTENSION)
self.assertTrue(response.context_data['token_fail'])

# When in XHR views, it should respond with a 400 bad request
Expand Down Expand Up @@ -265,7 +267,7 @@ def test_email_verification_mandatory(self):
self.assertGreater(mail.outbox[0].body.find('https://'), 0)
self.assertEqual(len(mail.outbox), 1)
self.assertTemplateUsed(resp,
'account/verification_sent.html')
'account/verification_sent.%s' % app_settings.TEMPLATE_EXTENSION)
# Attempt to login, unverified
for attempt in [1, 2]:
resp = c.post(reverse('account_login'),
Expand All @@ -278,8 +280,8 @@ def test_email_verification_mandatory(self):
self.assertTrue(get_user_model().objects.filter(
username='johndoe', is_active=True).exists())

self.assertTemplateUsed(resp,
'account/verification_sent.html')
self.assertTemplateUsed(
resp, 'account/verification_sent.%s' % app_settings.TEMPLATE_EXTENSION)
# Attempt 1: no mail is sent due to cool-down ,
# but there was already a mail in the outbox.
self.assertEqual(len(mail.outbox), attempt)
Expand All @@ -297,7 +299,7 @@ def test_email_verification_mandatory(self):
.get()
resp = c.get(reverse('account_confirm_email',
args=[confirmation.key]))
self.assertTemplateUsed(resp, 'account/email_confirm.html')
self.assertTemplateUsed(resp, 'account/email_confirm.%s' % app_settings.TEMPLATE_EXTENSION)
c.post(reverse('account_confirm_email',
args=[confirmation.key]))
resp = c.post(reverse('account_login'),
Expand Down Expand Up @@ -432,7 +434,7 @@ def test_logout_view_on_get(self):
@override_settings(ACCOUNT_LOGOUT_ON_GET=False)
def test_logout_view_on_post(self):
c, resp = self._logout_view('get')
self.assertTemplateUsed(resp, 'account/logout.html')
self.assertTemplateUsed(resp, 'account/logout.%s' % app_settings.TEMPLATE_EXTENSION)
resp = c.post(reverse('account_logout'))
self.assertTemplateUsed(resp, 'account/messages/logged_out.txt')

Expand Down
29 changes: 15 additions & 14 deletions allauth/account/views.py
Expand Up @@ -9,6 +9,7 @@
from django.shortcuts import redirect
from django.views.decorators.debug import sensitive_post_parameters
from django.utils.decorators import method_decorator
from django.conf import settings

from ..exceptions import ImmediateHttpResponse
from ..utils import get_form_class, get_request_param, get_current_site
Expand Down Expand Up @@ -87,7 +88,7 @@ class LoginView(RedirectAuthenticatedUserMixin,
AjaxCapableProcessFormViewMixin,
FormView):
form_class = LoginForm
template_name = "account/login.html"
template_name = "account/login.%s" % getattr(settings, 'ACCOUNT_TEMPLATE_EXTENSION', 'html')
success_url = None
redirect_field_name = "next"

Expand Down Expand Up @@ -131,7 +132,7 @@ def get_context_data(self, **kwargs):


class CloseableSignupMixin(object):
template_name_signup_closed = "account/signup_closed.html"
template_name_signup_closed = "account/signup_closed.%s" % getattr(settings, 'ACCOUNT_TEMPLATE_EXTENSION', 'html')

def dispatch(self, request, *args, **kwargs):
# WORKAROUND: https://code.djangoproject.com/ticket/19316
Expand Down Expand Up @@ -159,7 +160,7 @@ def closed(self):

class SignupView(RedirectAuthenticatedUserMixin, CloseableSignupMixin,
AjaxCapableProcessFormViewMixin, FormView):
template_name = "account/signup.html"
template_name = "account/signup.%s" % getattr(settings, 'ACCOUNT_TEMPLATE_EXTENSION', 'html')
form_class = SignupForm
redirect_field_name = "next"
success_url = None
Expand Down Expand Up @@ -205,7 +206,7 @@ def get_context_data(self, **kwargs):

class ConfirmEmailView(TemplateResponseMixin, View):

template_name = "account/email_confirm.html"
template_name = "account/email_confirm.%s" % getattr(settings, 'ACCOUNT_TEMPLATE_EXTENSION', 'html')

def get(self, *args, **kwargs):
try:
Expand Down Expand Up @@ -303,7 +304,7 @@ def get_redirect_url(self):


class EmailView(AjaxCapableProcessFormViewMixin, FormView):
template_name = "account/email.html"
template_name = "account/email.%s" % getattr(settings, 'ACCOUNT_TEMPLATE_EXTENSION', 'html')
form_class = AddEmailForm
success_url = reverse_lazy('account_email')

Expand Down Expand Up @@ -449,7 +450,7 @@ def get_context_data(self, **kwargs):


class PasswordChangeView(AjaxCapableProcessFormViewMixin, FormView):
template_name = "account/password_change.html"
template_name = "account/password_change.%s" % getattr(settings, 'ACCOUNT_TEMPLATE_EXTENSION', 'html')
form_class = ChangePasswordForm
success_url = reverse_lazy("account_change_password")

Expand Down Expand Up @@ -492,7 +493,7 @@ def get_context_data(self, **kwargs):


class PasswordSetView(AjaxCapableProcessFormViewMixin, FormView):
template_name = "account/password_set.html"
template_name = "account/password_set.%s" % getattr(settings, 'ACCOUNT_TEMPLATE_EXTENSION', 'html')
form_class = SetPasswordForm
success_url = reverse_lazy("account_set_password")

Expand Down Expand Up @@ -533,7 +534,7 @@ def get_context_data(self, **kwargs):


class PasswordResetView(AjaxCapableProcessFormViewMixin, FormView):
template_name = "account/password_reset.html"
template_name = "account/password_reset.%s" % getattr(settings, 'ACCOUNT_TEMPLATE_EXTENSION', 'html')
form_class = ResetPasswordForm
success_url = reverse_lazy("account_reset_password_done")

Expand All @@ -557,13 +558,13 @@ def get_context_data(self, **kwargs):


class PasswordResetDoneView(TemplateView):
template_name = "account/password_reset_done.html"
template_name = "account/password_reset_done.%s" % getattr(settings, 'ACCOUNT_TEMPLATE_EXTENSION', 'html')

password_reset_done = PasswordResetDoneView.as_view()


class PasswordResetFromKeyView(AjaxCapableProcessFormViewMixin, FormView):
template_name = "account/password_reset_from_key.html"
template_name = "account/password_reset_from_key.%s" % getattr(settings, 'ACCOUNT_TEMPLATE_EXTENSION', 'html')
form_class = ResetPasswordKeyForm
success_url = reverse_lazy("account_reset_password_from_key_done")

Expand Down Expand Up @@ -616,14 +617,14 @@ def form_valid(self, form):


class PasswordResetFromKeyDoneView(TemplateView):
template_name = "account/password_reset_from_key_done.html"
template_name = "account/password_reset_from_key_done.%s" % getattr(settings, 'ACCOUNT_TEMPLATE_EXTENSION', 'html')

password_reset_from_key_done = PasswordResetFromKeyDoneView.as_view()


class LogoutView(TemplateResponseMixin, View):

template_name = "account/logout.html"
template_name = "account/logout.%s" % getattr(settings, 'ACCOUNT_TEMPLATE_EXTENSION', 'html')
redirect_field_name = "next"

def get(self, *args, **kwargs):
Expand Down Expand Up @@ -664,12 +665,12 @@ def get_redirect_url(self):


class AccountInactiveView(TemplateView):
template_name = 'account/account_inactive.html'
template_name = 'account/account_inactive.%s' % getattr(settings, 'ACCOUNT_TEMPLATE_EXTENSION', 'html')

account_inactive = AccountInactiveView.as_view()


class EmailVerificationSentView(TemplateView):
template_name = 'account/verification_sent.html'
template_name = 'account/verification_sent.%s' % getattr(settings, 'ACCOUNT_TEMPLATE_EXTENSION', 'html')

email_verification_sent = EmailVerificationSentView.as_view()
8 changes: 5 additions & 3 deletions allauth/socialaccount/tests.py
Expand Up @@ -12,6 +12,7 @@
from django.contrib.messages.middleware import MessageMiddleware
from django.contrib.sessions.middleware import SessionMiddleware
from django.contrib.auth.models import AnonymousUser
from django.conf import settings

from ..tests import MockedResponse, mocked_response, TestCase
from ..account import app_settings as account_settings
Expand Down Expand Up @@ -104,7 +105,7 @@ def get_access_token_response(self):
def test_authentication_error(self):
resp = self.client.get(reverse(self.provider.id + '_callback'))
self.assertTemplateUsed(resp,
'socialaccount/authentication_error.html')
'socialaccount/authentication_error.%s' % getattr(settings, 'ACCOUNT_TEMPLATE_EXTENSION', 'html'))


# For backward-compatibility with third-party provider tests that call
Expand Down Expand Up @@ -215,8 +216,9 @@ def login(self, resp_mock, process='login',

def test_authentication_error(self):
resp = self.client.get(reverse(self.provider.id + '_callback'))
self.assertTemplateUsed(resp,
'socialaccount/authentication_error.html')
self.assertTemplateUsed(
resp,
'socialaccount/authentication_error.%s' % getattr(settings, 'ACCOUNT_TEMPLATE_EXTENSION', 'html'))


# For backward-compatibility with third-party provider tests that call
Expand Down
9 changes: 5 additions & 4 deletions allauth/socialaccount/views.py
Expand Up @@ -4,6 +4,7 @@
from django.contrib.auth.decorators import login_required
from django.views.generic.base import TemplateView
from django.views.generic.edit import FormView
from django.conf import settings

from ..account.views import (AjaxCapableProcessFormViewMixin,
CloseableSignupMixin,
Expand All @@ -21,7 +22,7 @@
class SignupView(RedirectAuthenticatedUserMixin, CloseableSignupMixin,
AjaxCapableProcessFormViewMixin, FormView):
form_class = SignupForm
template_name = 'socialaccount/signup.html'
template_name = 'socialaccount/signup.%s' % getattr(settings, 'ACCOUNT_TEMPLATE_EXTENSION', 'html')

def get_form_class(self):
return get_form_class(app_settings.FORMS,
Expand Down Expand Up @@ -64,20 +65,20 @@ def get_authenticated_redirect_url(self):


class LoginCancelledView(TemplateView):
template_name = "socialaccount/login_cancelled.html"
template_name = "socialaccount/login_cancelled.%s" % getattr(settings, 'ACCOUNT_TEMPLATE_EXTENSION', 'html')

login_cancelled = LoginCancelledView.as_view()


class LoginErrorView(TemplateView):
template_name = "socialaccount/authentication_error.html"
template_name = "socialaccount/authentication_error.%s" % getattr(settings, 'ACCOUNT_TEMPLATE_EXTENSION', 'html')


login_error = LoginErrorView.as_view()


class ConnectionsView(AjaxCapableProcessFormViewMixin, FormView):
template_name = "socialaccount/connections.html"
template_name = "socialaccount/connections.%s" % getattr(settings, 'ACCOUNT_TEMPLATE_EXTENSION', 'html')
form_class = DisconnectForm
success_url = reverse_lazy("socialaccount_connections")

Expand Down
3 changes: 3 additions & 0 deletions docs/configuration.rst
Expand Up @@ -140,6 +140,9 @@ ACCOUNT_AUTHENTICATED_LOGIN_REDIRECTS( (=True)
By changing this setting to `False`, logged in users will not be redirected when
they access login/signup pages.

ACCOUNT_TEMPLATE_EXTENSION (="html")
A string defining the template extension to use, defaults to `html`.

SOCIALACCOUNT_ADAPTER (="allauth.socialaccount.adapter.DefaultSocialAccountAdapter")
Specifies the adapter class to use, allowing you to alter certain
default behaviour.
Expand Down

0 comments on commit aab22a2

Please sign in to comment.