From d08977a0f05cf3efb538dcb09d07915d2ede4c67 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Mon, 11 Jan 2021 12:27:40 +0100 Subject: [PATCH] Refs #30997 -- Removed HttpRequest.is_ajax() per deprecation timeline. --- django/http/request.py | 11 ----------- docs/ref/request-response.txt | 17 ----------------- docs/releases/4.0.txt | 2 ++ tests/requests/test_is_ajax_deprecations.py | 12 ------------ 4 files changed, 2 insertions(+), 40 deletions(-) delete mode 100644 tests/requests/test_is_ajax_deprecations.py diff --git a/django/http/request.py b/django/http/request.py index 2488bf9ccdf..bdf9b508b1e 100644 --- a/django/http/request.py +++ b/django/http/request.py @@ -1,7 +1,6 @@ import cgi import codecs import copy -import warnings from io import BytesIO from itertools import chain from urllib.parse import parse_qsl, quote, urlencode, urljoin, urlsplit @@ -16,7 +15,6 @@ from django.http.multipartparser import MultiPartParser, MultiPartParserError from django.utils.datastructures import ( CaseInsensitiveMapping, ImmutableList, MultiValueDict, ) -from django.utils.deprecation import RemovedInDjango40Warning from django.utils.encoding import escape_uri_path, iri_to_uri from django.utils.functional import cached_property from django.utils.http import is_same_domain @@ -266,15 +264,6 @@ class HttpRequest: def is_secure(self): return self.scheme == 'https' - def is_ajax(self): - warnings.warn( - 'request.is_ajax() is deprecated. See Django 3.1 release notes ' - 'for more details about this deprecation.', - RemovedInDjango40Warning, - stacklevel=2, - ) - return self.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest' - @property def encoding(self): return self._encoding diff --git a/docs/ref/request-response.txt b/docs/ref/request-response.txt index 819272bd6e8..4f4de1be1ce 100644 --- a/docs/ref/request-response.txt +++ b/docs/ref/request-response.txt @@ -425,23 +425,6 @@ Methods ` so that the responses are properly cached. -.. method:: HttpRequest.is_ajax() - - .. deprecated:: 3.1 - - Returns ``True`` if the request was made via an ``XMLHttpRequest``, by - checking the ``HTTP_X_REQUESTED_WITH`` header for the string - ``'XMLHttpRequest'``. Most modern JavaScript libraries send this header. - If you write your own ``XMLHttpRequest`` call (on the browser side), you'll - have to set this header manually if you want ``is_ajax()`` to work. - - If a response varies on whether or not it's requested via AJAX and you are - using some form of caching like Django's :mod:`cache middleware - `, you should decorate the view with - :func:`vary_on_headers('X-Requested-With') - ` so that the responses are - properly cached. - .. method:: HttpRequest.read(size=None) .. method:: HttpRequest.readline() .. method:: HttpRequest.readlines() diff --git a/docs/releases/4.0.txt b/docs/releases/4.0.txt index f5fb3e06e8b..34eb8acd959 100644 --- a/docs/releases/4.0.txt +++ b/docs/releases/4.0.txt @@ -275,3 +275,5 @@ to remove usage of these features. * The ``django.db.models.query_utils.InvalidQuery`` exception class is removed. * The ``django-admin.py`` entry point is removed. + +* The ``HttpRequest.is_ajax()`` method is removed. diff --git a/tests/requests/test_is_ajax_deprecations.py b/tests/requests/test_is_ajax_deprecations.py deleted file mode 100644 index e311752d7f1..00000000000 --- a/tests/requests/test_is_ajax_deprecations.py +++ /dev/null @@ -1,12 +0,0 @@ -from django.http import HttpRequest -from django.test import SimpleTestCase, ignore_warnings -from django.utils.deprecation import RemovedInDjango40Warning - - -@ignore_warnings(category=RemovedInDjango40Warning) -class TestDeprecatedIsAjax(SimpleTestCase): - def test_is_ajax(self): - request = HttpRequest() - self.assertIs(request.is_ajax(), False) - request.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest' - self.assertIs(request.is_ajax(), True)