1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Refs #32375 -- Changed default sitemap protocol to https.

Per deprecation timeline.
This commit is contained in:
Mariusz Felisiak 2023-01-06 12:55:14 +01:00
parent 602d9a312f
commit 4eb97a90f0
5 changed files with 10 additions and 34 deletions

View File

@ -1,4 +1,3 @@
import warnings
from urllib.parse import urlencode
from urllib.request import urlopen
@ -8,7 +7,6 @@ from django.core import paginator
from django.core.exceptions import ImproperlyConfigured
from django.urls import NoReverseMatch, reverse
from django.utils import translation
from django.utils.deprecation import RemovedInDjango50Warning
PING_URL = "https://www.google.com/webmasters/tools/ping"
@ -133,17 +131,7 @@ class Sitemap:
def get_protocol(self, protocol=None):
# Determine protocol
if self.protocol is None and protocol is None:
warnings.warn(
"The default sitemap protocol will be changed from 'http' to "
"'https' in Django 5.0. Set Sitemap.protocol to silence this "
"warning.",
category=RemovedInDjango50Warning,
stacklevel=2,
)
# RemovedInDjango50Warning: when the deprecation ends, replace 'http'
# with 'https'.
return self.protocol or protocol or "http"
return self.protocol or protocol or "https"
def get_domain(self, site=None):
# Determine domain

View File

@ -242,12 +242,12 @@ Note:
This attribute defines the protocol (``'http'`` or ``'https'``) of the
URLs in the sitemap. If it isn't set, the protocol with which the
sitemap was requested is used. If the sitemap is built outside the
context of a request, the default is ``'http'``.
context of a request, the default is ``'https'``.
.. deprecated:: 4.0
.. versionchanged:: 5.0
The default protocol for sitemaps built outside the context of a
request will change from ``'http'`` to ``'https'`` in Django 5.0.
In older versions, the default protocol for sitemaps built outside
the context of a request was ``'http'``.
.. attribute:: Sitemap.limit

View File

@ -264,6 +264,9 @@ to remove usage of these features.
* The default value of the ``USE_TZ`` setting is changed from ``False`` to
``True``.
* The default sitemap protocol for sitemaps built outside the context of a
request is changed from ``'http'`` to ``'https'``.
See :ref:`deprecated-features-4.1` for details on these changes, including how
to remove usage of these features.

View File

@ -1,8 +1,7 @@
from datetime import datetime
from django.contrib.sitemaps import GenericSitemap
from django.test import ignore_warnings, override_settings
from django.utils.deprecation import RemovedInDjango50Warning
from django.test import override_settings
from .base import SitemapTestsBase
from .models import TestModel
@ -79,20 +78,9 @@ class GenericViewsSitemapTests(SitemapTestsBase):
with self.subTest(protocol=protocol):
self.assertEqual(sitemap.get_protocol(protocol), protocol)
@ignore_warnings(category=RemovedInDjango50Warning)
def test_get_protocol_default(self):
sitemap = GenericSitemap({"queryset": None})
self.assertEqual(sitemap.get_protocol(), "http")
def test_get_protocol_default_warning(self):
sitemap = GenericSitemap({"queryset": None})
msg = (
"The default sitemap protocol will be changed from 'http' to "
"'https' in Django 5.0. Set Sitemap.protocol to silence this "
"warning."
)
with self.assertWarnsMessage(RemovedInDjango50Warning, msg):
sitemap.get_protocol()
self.assertEqual(sitemap.get_protocol(), "https")
def test_generic_sitemap_index(self):
TestModel.objects.update(lastmod=datetime(2013, 3, 13, 10, 0, 0))

View File

@ -271,7 +271,6 @@ class HTTPSitemapTests(SitemapTestsBase):
) % date.today()
self.assertXMLEqual(response.content.decode(), expected_content)
@ignore_warnings(category=RemovedInDjango50Warning)
def test_sitemap_get_urls_no_site_1(self):
"""
Check we get ImproperlyConfigured if we don't pass a site object to
@ -282,7 +281,6 @@ class HTTPSitemapTests(SitemapTestsBase):
Sitemap().get_urls()
@modify_settings(INSTALLED_APPS={"remove": "django.contrib.sites"})
@ignore_warnings(category=RemovedInDjango50Warning)
def test_sitemap_get_urls_no_site_2(self):
"""
Check we get ImproperlyConfigured when we don't pass a site object to
@ -292,7 +290,6 @@ class HTTPSitemapTests(SitemapTestsBase):
with self.assertRaisesMessage(ImproperlyConfigured, self.use_sitemap_err_msg):
Sitemap().get_urls()
@ignore_warnings(category=RemovedInDjango50Warning)
def test_sitemap_item(self):
"""
Check to make sure that the raw item is included with each