mirror of
				https://github.com/django/django.git
				synced 2025-11-04 13:39:16 +00:00 
			
		
		
		
	Refs #30997 -- Removed HttpRequest.is_ajax() per deprecation timeline.
This commit is contained in:
		
							parent
							
								
									90c59b4e12
								
							
						
					
					
						commit
						d08977a0f0
					
				
					 4 changed files with 2 additions and 40 deletions
				
			
		| 
						 | 
					@ -1,7 +1,6 @@
 | 
				
			||||||
import cgi
 | 
					import cgi
 | 
				
			||||||
import codecs
 | 
					import codecs
 | 
				
			||||||
import copy
 | 
					import copy
 | 
				
			||||||
import warnings
 | 
					 | 
				
			||||||
from io import BytesIO
 | 
					from io import BytesIO
 | 
				
			||||||
from itertools import chain
 | 
					from itertools import chain
 | 
				
			||||||
from urllib.parse import parse_qsl, quote, urlencode, urljoin, urlsplit
 | 
					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 (
 | 
					from django.utils.datastructures import (
 | 
				
			||||||
    CaseInsensitiveMapping, ImmutableList, MultiValueDict,
 | 
					    CaseInsensitiveMapping, ImmutableList, MultiValueDict,
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
from django.utils.deprecation import RemovedInDjango40Warning
 | 
					 | 
				
			||||||
from django.utils.encoding import escape_uri_path, iri_to_uri
 | 
					from django.utils.encoding import escape_uri_path, iri_to_uri
 | 
				
			||||||
from django.utils.functional import cached_property
 | 
					from django.utils.functional import cached_property
 | 
				
			||||||
from django.utils.http import is_same_domain
 | 
					from django.utils.http import is_same_domain
 | 
				
			||||||
| 
						 | 
					@ -266,15 +264,6 @@ class HttpRequest:
 | 
				
			||||||
    def is_secure(self):
 | 
					    def is_secure(self):
 | 
				
			||||||
        return self.scheme == 'https'
 | 
					        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
 | 
					    @property
 | 
				
			||||||
    def encoding(self):
 | 
					    def encoding(self):
 | 
				
			||||||
        return self._encoding
 | 
					        return self._encoding
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -425,23 +425,6 @@ Methods
 | 
				
			||||||
    <django.views.decorators.vary.vary_on_headers>` so that the responses are
 | 
					    <django.views.decorators.vary.vary_on_headers>` so that the responses are
 | 
				
			||||||
    properly cached.
 | 
					    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
 | 
					 | 
				
			||||||
    <django.middleware.cache>`, you should decorate the view with
 | 
					 | 
				
			||||||
    :func:`vary_on_headers('X-Requested-With')
 | 
					 | 
				
			||||||
    <django.views.decorators.vary.vary_on_headers>` so that the responses are
 | 
					 | 
				
			||||||
    properly cached.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
.. method:: HttpRequest.read(size=None)
 | 
					.. method:: HttpRequest.read(size=None)
 | 
				
			||||||
.. method:: HttpRequest.readline()
 | 
					.. method:: HttpRequest.readline()
 | 
				
			||||||
.. method:: HttpRequest.readlines()
 | 
					.. method:: HttpRequest.readlines()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -275,3 +275,5 @@ to remove usage of these features.
 | 
				
			||||||
* The ``django.db.models.query_utils.InvalidQuery`` exception class is removed.
 | 
					* The ``django.db.models.query_utils.InvalidQuery`` exception class is removed.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* The ``django-admin.py`` entry point is removed.
 | 
					* The ``django-admin.py`` entry point is removed.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					* The ``HttpRequest.is_ajax()`` method is removed.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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)
 | 
					 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue