From 2013a153dbf4ed5480bd3a51154ecb59bee19f1f Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Thu, 12 Jan 2023 12:34:42 +0100 Subject: [PATCH] Refs #25916 -- Removed SitemapIndexItem.__str__() per deprecation timeline. --- django/contrib/sitemaps/views.py | 11 ----- docs/releases/5.0.txt | 2 +- .../templates/custom_sitemap_index.xml | 5 --- tests/sitemaps_tests/test_http.py | 44 +------------------ tests/sitemaps_tests/urls/http.py | 5 --- 5 files changed, 2 insertions(+), 65 deletions(-) delete mode 100644 tests/sitemaps_tests/templates/custom_sitemap_index.xml diff --git a/django/contrib/sitemaps/views.py b/django/contrib/sitemaps/views.py index 679f7ed611..d696639932 100644 --- a/django/contrib/sitemaps/views.py +++ b/django/contrib/sitemaps/views.py @@ -1,5 +1,4 @@ import datetime -import warnings from dataclasses import dataclass from functools import wraps @@ -9,7 +8,6 @@ from django.http import Http404 from django.template.response import TemplateResponse from django.urls import reverse from django.utils import timezone -from django.utils.deprecation import RemovedInDjango50Warning from django.utils.http import http_date @@ -18,15 +16,6 @@ class SitemapIndexItem: location: str last_mod: bool = None - # RemovedInDjango50Warning - def __str__(self): - msg = ( - "Calling `__str__` on SitemapIndexItem is deprecated, use the `location` " - "attribute instead." - ) - warnings.warn(msg, RemovedInDjango50Warning, stacklevel=2) - return self.location - def x_robots_tag(func): @wraps(func) diff --git a/docs/releases/5.0.txt b/docs/releases/5.0.txt index 9fc612f418..f5b4f532a9 100644 --- a/docs/releases/5.0.txt +++ b/docs/releases/5.0.txt @@ -305,4 +305,4 @@ to remove usage of these features. See :ref:`deprecated-features-4.1` for details on these changes, including how to remove usage of these features. -* ... +* The ``SitemapIndexItem.__str__()`` method is removed. diff --git a/tests/sitemaps_tests/templates/custom_sitemap_index.xml b/tests/sitemaps_tests/templates/custom_sitemap_index.xml deleted file mode 100644 index 406c6b7606..0000000000 --- a/tests/sitemaps_tests/templates/custom_sitemap_index.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - -{% for location in sitemaps %}{{ location }}{% endfor %} - diff --git a/tests/sitemaps_tests/test_http.py b/tests/sitemaps_tests/test_http.py index 1a0c1c3d50..74d183a7b0 100644 --- a/tests/sitemaps_tests/test_http.py +++ b/tests/sitemaps_tests/test_http.py @@ -4,9 +4,8 @@ from datetime import date from django.contrib.sitemaps import Sitemap from django.contrib.sites.models import Site from django.core.exceptions import ImproperlyConfigured -from django.test import ignore_warnings, modify_settings, override_settings +from django.test import modify_settings, override_settings from django.utils import translation -from django.utils.deprecation import RemovedInDjango50Warning from django.utils.formats import localize from .base import SitemapTestsBase @@ -579,44 +578,3 @@ class HTTPSitemapTests(SitemapTestsBase): """ self.assertXMLEqual(index_response.content.decode(), expected_content_index) - - -# RemovedInDjango50Warning -class DeprecatedTests(SitemapTestsBase): - @override_settings( - TEMPLATES=[ - { - "BACKEND": "django.template.backends.django.DjangoTemplates", - "DIRS": [os.path.join(os.path.dirname(__file__), "templates")], - } - ] - ) - def test_simple_sitemap_custom_index_warning(self): - msg = ( - "Calling `__str__` on SitemapIndexItem is deprecated, use the `location` " - "attribute instead." - ) - with self.assertRaisesMessage(RemovedInDjango50Warning, msg): - self.client.get("/simple/custom-index.xml") - - @ignore_warnings(category=RemovedInDjango50Warning) - @override_settings( - TEMPLATES=[ - { - "BACKEND": "django.template.backends.django.DjangoTemplates", - "DIRS": [os.path.join(os.path.dirname(__file__), "templates")], - } - ] - ) - def test_simple_sitemap_custom_index(self): - "A simple sitemap index can be rendered with a custom template" - response = self.client.get("/simple/custom-index.xml") - expected_content = """ - - - %s/simple/sitemap-simple.xml - - """ % ( - self.base_url - ) - self.assertXMLEqual(response.content.decode(), expected_content) diff --git a/tests/sitemaps_tests/urls/http.py b/tests/sitemaps_tests/urls/http.py index 2b512cfd69..db549b4a38 100644 --- a/tests/sitemaps_tests/urls/http.py +++ b/tests/sitemaps_tests/urls/http.py @@ -279,11 +279,6 @@ urlpatterns = [ views.index, {"sitemaps": simple_sitemaps_not_callable}, ), - path( - "simple/custom-index.xml", - views.index, - {"sitemaps": simple_sitemaps, "template_name": "custom_sitemap_index.xml"}, - ), path( "simple/custom-lastmod-index.xml", views.index,