Fixed #26929 -- Deprecated extra_context parameter of contrib.auth.views.logout_then_login().

This commit is contained in:
Andrew Nester 2016-07-22 17:43:54 +03:00 committed by Tim Graham
parent 412b4126d7
commit 0ba179194b
5 changed files with 26 additions and 1 deletions

View File

@ -177,11 +177,20 @@ def logout(request, *args, **kwargs):
return LogoutView.as_view(**kwargs)(request, *args, **kwargs)
_sentinel = object()
@deprecate_current_app
def logout_then_login(request, login_url=None, extra_context=None):
def logout_then_login(request, login_url=None, extra_context=_sentinel):
"""
Logs out the user if they are logged in. Then redirects to the log-in page.
"""
if extra_context is not _sentinel:
warnings.warn(
"The unused `extra_context` parameter to `logout_then_login` "
"is deprecated.", RemovedInDjango21Warning
)
if not login_url:
login_url = settings.LOGIN_URL
login_url = resolve_url(login_url)

View File

@ -20,6 +20,9 @@ details on these changes.
``password_reset_confirm()``, and ``password_reset_complete()`` will be
removed.
* The ``extra_context`` parameter of ``contrib.auth.views.logout_then_login()``
will be removed.
.. _deprecation-removed-in-2.0:
2.0

View File

@ -366,6 +366,9 @@ Miscellaneous
:class:`~django.contrib.auth.views.LoginView` and
:class:`~django.contrib.auth.views.LogoutView`.
* The unused ``extra_context`` parameter of
``contrib.auth.views.logout_then_login()`` is deprecated.
* ``contrib.auth``s ``password_change()``, ``password_change_done()``,
``password_reset()``, ``password_reset_done()``, ``password_reset_confirm()``,
and ``password_reset_complete()`` function-based views are deprecated in favor

View File

@ -1179,6 +1179,11 @@ implementation details see :ref:`using-the-views`.
The ``current_app`` parameter is deprecated and will be removed in
Django 2.0. Callers should set ``request.current_app`` instead.
.. deprecated:: 1.11
The unused ``extra_context`` parameter is deprecated and will be
removed in Django 2.1.
.. function:: password_change(request, template_name='registration/password_change_form.html', post_change_redirect=None, password_change_form=PasswordChangeForm, current_app=None, extra_context=None)
.. deprecated:: 1.11

View File

@ -27,6 +27,7 @@ from django.middleware.csrf import CsrfViewMiddleware, get_token
from django.test import TestCase, override_settings
from django.test.utils import patch_logger
from django.urls import NoReverseMatch, reverse, reverse_lazy
from django.utils.deprecation import RemovedInDjango21Warning
from django.utils.encoding import force_text
from django.utils.http import urlquote
from django.utils.six.moves.urllib.parse import ParseResult, urlparse
@ -734,6 +735,10 @@ class LogoutThenLoginTests(AuthViewsTestCase):
self.confirm_logged_out()
self.assertRedirects(response, '/custom/', fetch_redirect_response=False)
def test_deprecated_extra_context(self):
with self.assertRaisesMessage(RemovedInDjango21Warning, 'The unused `extra_context` parameter'):
logout_then_login(None, extra_context={})
class LoginRedirectAuthenticatedUser(AuthViewsTestCase):
dont_redirect_url = '/login/redirect_authenticated_user_default/'