mirror of
https://github.com/django/django.git
synced 2025-06-03 18:49:12 +00:00
Refs #25916 -- Removed SitemapIndexItem.__str__() per deprecation timeline.
This commit is contained in:
parent
31878b4d73
commit
daf88e778b
@ -1,5 +1,4 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import warnings
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
@ -9,7 +8,6 @@ from django.http import Http404
|
|||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.deprecation import RemovedInDjango50Warning
|
|
||||||
from django.utils.http import http_date
|
from django.utils.http import http_date
|
||||||
|
|
||||||
|
|
||||||
@ -18,15 +16,6 @@ class SitemapIndexItem:
|
|||||||
location: str
|
location: str
|
||||||
last_mod: bool = None
|
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):
|
def x_robots_tag(func):
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
|
@ -305,4 +305,4 @@ to remove usage of these features.
|
|||||||
See :ref:`deprecated-features-4.1` for details on these changes, including how
|
See :ref:`deprecated-features-4.1` for details on these changes, including how
|
||||||
to remove usage of these features.
|
to remove usage of these features.
|
||||||
|
|
||||||
* ...
|
* The ``SitemapIndexItem.__str__()`` method is removed.
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!-- This is a customised template -->
|
|
||||||
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
||||||
{% for location in sitemaps %}<sitemap><loc>{{ location }}</loc></sitemap>{% endfor %}
|
|
||||||
</sitemapindex>
|
|
@ -4,9 +4,8 @@ from datetime import date
|
|||||||
from django.contrib.sitemaps import Sitemap
|
from django.contrib.sitemaps import Sitemap
|
||||||
from django.contrib.sites.models import Site
|
from django.contrib.sites.models import Site
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
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 import translation
|
||||||
from django.utils.deprecation import RemovedInDjango50Warning
|
|
||||||
from django.utils.formats import localize
|
from django.utils.formats import localize
|
||||||
|
|
||||||
from .base import SitemapTestsBase
|
from .base import SitemapTestsBase
|
||||||
@ -579,44 +578,3 @@ class HTTPSitemapTests(SitemapTestsBase):
|
|||||||
</sitemapindex>
|
</sitemapindex>
|
||||||
"""
|
"""
|
||||||
self.assertXMLEqual(index_response.content.decode(), expected_content_index)
|
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 = """<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!-- This is a customised template -->
|
|
||||||
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
||||||
<sitemap><loc>%s/simple/sitemap-simple.xml</loc></sitemap>
|
|
||||||
</sitemapindex>
|
|
||||||
""" % (
|
|
||||||
self.base_url
|
|
||||||
)
|
|
||||||
self.assertXMLEqual(response.content.decode(), expected_content)
|
|
||||||
|
@ -279,11 +279,6 @@ urlpatterns = [
|
|||||||
views.index,
|
views.index,
|
||||||
{"sitemaps": simple_sitemaps_not_callable},
|
{"sitemaps": simple_sitemaps_not_callable},
|
||||||
),
|
),
|
||||||
path(
|
|
||||||
"simple/custom-index.xml",
|
|
||||||
views.index,
|
|
||||||
{"sitemaps": simple_sitemaps, "template_name": "custom_sitemap_index.xml"},
|
|
||||||
),
|
|
||||||
path(
|
path(
|
||||||
"simple/custom-lastmod-index.xml",
|
"simple/custom-lastmod-index.xml",
|
||||||
views.index,
|
views.index,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user