1
0
mirror of https://github.com/django/django.git synced 2025-05-05 14:37:31 +00:00

Refs #26929 -- Removed extra_context parameter of contrib.auth.views.logout_then_login().

Per deprecation timeline.
This commit is contained in:
Tim Graham 2017-09-02 19:45:09 -04:00
parent 4f313e284e
commit 6e40b70bf4
4 changed files with 5 additions and 26 deletions

View File

@ -1,4 +1,3 @@
import warnings
from urllib.parse import urlparse, urlunparse from urllib.parse import urlparse, urlunparse
from django.conf import settings from django.conf import settings
@ -17,7 +16,6 @@ from django.http import HttpResponseRedirect, QueryDict
from django.shortcuts import resolve_url from django.shortcuts import resolve_url
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.utils.deprecation import RemovedInDjango21Warning
from django.utils.http import is_safe_url, urlsafe_base64_decode from django.utils.http import is_safe_url, urlsafe_base64_decode
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views.decorators.cache import never_cache from django.views.decorators.cache import never_cache
@ -166,19 +164,10 @@ class LogoutView(SuccessURLAllowedHostsMixin, TemplateView):
return context return context
_sentinel = object() def logout_then_login(request, login_url=None):
def logout_then_login(request, login_url=None, extra_context=_sentinel):
""" """
Log out the user if they are logged in. Then redirect to the login page. Log out the user if they are logged in. Then redirect to the login 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)

View File

@ -229,3 +229,6 @@ how to remove usage of these features.
* ``contrib.auth.views.login()``, ``logout()``, ``password_change()``, * ``contrib.auth.views.login()``, ``logout()``, ``password_change()``,
``password_change_done()``, ``password_reset()``, ``password_reset_done()``, ``password_change_done()``, ``password_reset()``, ``password_reset_done()``,
``password_reset_confirm()``, and ``password_reset_complete()`` are removed. ``password_reset_confirm()``, and ``password_reset_complete()`` are removed.
* The ``extra_context`` parameter of ``contrib.auth.views.logout_then_login()``
is removed.

View File

@ -1126,7 +1126,7 @@ implementation details see :ref:`using-the-views`.
:attr:`request.META['SERVER_NAME'] <django.http.HttpRequest.META>`. :attr:`request.META['SERVER_NAME'] <django.http.HttpRequest.META>`.
For more on sites, see :doc:`/ref/contrib/sites`. For more on sites, see :doc:`/ref/contrib/sites`.
.. function:: logout_then_login(request, login_url=None, extra_context=None) .. function:: logout_then_login(request, login_url=None)
Logs a user out, then redirects to the login page. Logs a user out, then redirects to the login page.
@ -1137,14 +1137,6 @@ implementation details see :ref:`using-the-views`.
* ``login_url``: The URL of the login page to redirect to. * ``login_url``: The URL of the login page to redirect to.
Defaults to :setting:`settings.LOGIN_URL <LOGIN_URL>` if not supplied. Defaults to :setting:`settings.LOGIN_URL <LOGIN_URL>` if not supplied.
* ``extra_context``: A dictionary of context data that will be added to the
default context data passed to the template.
.. deprecated:: 1.11
The unused ``extra_context`` parameter is deprecated and will be
removed in Django 2.1.
.. class:: PasswordChangeView .. class:: PasswordChangeView
.. versionadded:: 1.11 .. versionadded:: 1.11

View File

@ -28,7 +28,6 @@ from django.middleware.csrf import CsrfViewMiddleware, get_token
from django.test import Client, TestCase, override_settings from django.test import Client, 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.translation import LANGUAGE_SESSION_KEY from django.utils.translation import LANGUAGE_SESSION_KEY
@ -821,10 +820,6 @@ 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/'