1
0
mirror of https://github.com/django/django.git synced 2025-03-31 19:46:42 +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.parse import urlencode
from urllib.request import urlopen from urllib.request import urlopen
@ -8,7 +7,6 @@ from django.core import paginator
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.urls import NoReverseMatch, reverse from django.urls import NoReverseMatch, reverse
from django.utils import translation from django.utils import translation
from django.utils.deprecation import RemovedInDjango50Warning
PING_URL = "https://www.google.com/webmasters/tools/ping" PING_URL = "https://www.google.com/webmasters/tools/ping"
@ -133,17 +131,7 @@ class Sitemap:
def get_protocol(self, protocol=None): def get_protocol(self, protocol=None):
# Determine protocol # Determine protocol
if self.protocol is None and protocol is None: return self.protocol or protocol or "https"
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"
def get_domain(self, site=None): def get_domain(self, site=None):
# Determine domain # Determine domain

View File

@ -242,12 +242,12 @@ Note:
This attribute defines the protocol (``'http'`` or ``'https'``) of the This attribute defines the protocol (``'http'`` or ``'https'``) of the
URLs in the sitemap. If it isn't set, the protocol with which 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 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 In older versions, the default protocol for sitemaps built outside
request will change from ``'http'`` to ``'https'`` in Django 5.0. the context of a request was ``'http'``.
.. attribute:: Sitemap.limit .. 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 * The default value of the ``USE_TZ`` setting is changed from ``False`` to
``True``. ``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 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.

View File

@ -1,8 +1,7 @@
from datetime import datetime from datetime import datetime
from django.contrib.sitemaps import GenericSitemap from django.contrib.sitemaps import GenericSitemap
from django.test import ignore_warnings, override_settings from django.test import override_settings
from django.utils.deprecation import RemovedInDjango50Warning
from .base import SitemapTestsBase from .base import SitemapTestsBase
from .models import TestModel from .models import TestModel
@ -79,20 +78,9 @@ class GenericViewsSitemapTests(SitemapTestsBase):
with self.subTest(protocol=protocol): with self.subTest(protocol=protocol):
self.assertEqual(sitemap.get_protocol(protocol), protocol) self.assertEqual(sitemap.get_protocol(protocol), protocol)
@ignore_warnings(category=RemovedInDjango50Warning)
def test_get_protocol_default(self): def test_get_protocol_default(self):
sitemap = GenericSitemap({"queryset": None}) sitemap = GenericSitemap({"queryset": None})
self.assertEqual(sitemap.get_protocol(), "http") self.assertEqual(sitemap.get_protocol(), "https")
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()
def test_generic_sitemap_index(self): def test_generic_sitemap_index(self):
TestModel.objects.update(lastmod=datetime(2013, 3, 13, 10, 0, 0)) TestModel.objects.update(lastmod=datetime(2013, 3, 13, 10, 0, 0))

View File

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