mirror of
https://github.com/django/django.git
synced 2025-06-08 13:09:13 +00:00
Fixed #26929 -- Deprecated extra_context parameter of contrib.auth.views.logout_then_login().
This commit is contained in:
parent
412b4126d7
commit
0ba179194b
@ -177,11 +177,20 @@ def logout(request, *args, **kwargs):
|
|||||||
return LogoutView.as_view(**kwargs)(request, *args, **kwargs)
|
return LogoutView.as_view(**kwargs)(request, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
_sentinel = object()
|
||||||
|
|
||||||
|
|
||||||
@deprecate_current_app
|
@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.
|
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:
|
if not login_url:
|
||||||
login_url = settings.LOGIN_URL
|
login_url = settings.LOGIN_URL
|
||||||
login_url = resolve_url(login_url)
|
login_url = resolve_url(login_url)
|
||||||
|
@ -20,6 +20,9 @@ details on these changes.
|
|||||||
``password_reset_confirm()``, and ``password_reset_complete()`` will be
|
``password_reset_confirm()``, and ``password_reset_complete()`` will be
|
||||||
removed.
|
removed.
|
||||||
|
|
||||||
|
* The ``extra_context`` parameter of ``contrib.auth.views.logout_then_login()``
|
||||||
|
will be removed.
|
||||||
|
|
||||||
.. _deprecation-removed-in-2.0:
|
.. _deprecation-removed-in-2.0:
|
||||||
|
|
||||||
2.0
|
2.0
|
||||||
|
@ -366,6 +366,9 @@ Miscellaneous
|
|||||||
:class:`~django.contrib.auth.views.LoginView` and
|
:class:`~django.contrib.auth.views.LoginView` and
|
||||||
:class:`~django.contrib.auth.views.LogoutView`.
|
: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()``,
|
* ``contrib.auth``’s ``password_change()``, ``password_change_done()``,
|
||||||
``password_reset()``, ``password_reset_done()``, ``password_reset_confirm()``,
|
``password_reset()``, ``password_reset_done()``, ``password_reset_confirm()``,
|
||||||
and ``password_reset_complete()`` function-based views are deprecated in favor
|
and ``password_reset_complete()`` function-based views are deprecated in favor
|
||||||
|
@ -1179,6 +1179,11 @@ implementation details see :ref:`using-the-views`.
|
|||||||
The ``current_app`` parameter is deprecated and will be removed in
|
The ``current_app`` parameter is deprecated and will be removed in
|
||||||
Django 2.0. Callers should set ``request.current_app`` instead.
|
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)
|
.. 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
|
.. deprecated:: 1.11
|
||||||
|
@ -27,6 +27,7 @@ from django.middleware.csrf import CsrfViewMiddleware, get_token
|
|||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
from django.test.utils import patch_logger
|
from django.test.utils import patch_logger
|
||||||
from django.urls import NoReverseMatch, reverse, reverse_lazy
|
from django.urls import NoReverseMatch, reverse, reverse_lazy
|
||||||
|
from django.utils.deprecation import RemovedInDjango21Warning
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_text
|
||||||
from django.utils.http import urlquote
|
from django.utils.http import urlquote
|
||||||
from django.utils.six.moves.urllib.parse import ParseResult, urlparse
|
from django.utils.six.moves.urllib.parse import ParseResult, urlparse
|
||||||
@ -734,6 +735,10 @@ class LogoutThenLoginTests(AuthViewsTestCase):
|
|||||||
self.confirm_logged_out()
|
self.confirm_logged_out()
|
||||||
self.assertRedirects(response, '/custom/', fetch_redirect_response=False)
|
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):
|
class LoginRedirectAuthenticatedUser(AuthViewsTestCase):
|
||||||
dont_redirect_url = '/login/redirect_authenticated_user_default/'
|
dont_redirect_url = '/login/redirect_authenticated_user_default/'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user