1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

[4.1.x] Fixed #34088 -- Fixed Sitemap.get_latest_lastmod() crash with empty items.

Bug in 480191244d.

Thanks Michal Čihař for the report.

Backport of 5eab4d1924 from main
This commit is contained in:
Daniel Ivanov
2022-11-04 16:43:40 +03:00
committed by Mariusz Felisiak
parent 84a2b2e7a7
commit eca526eab0
4 changed files with 35 additions and 1 deletions

View File

@@ -114,6 +114,16 @@ class CallableLastmodFullSitemap(Sitemap):
return obj.lastmod
class CallableLastmodNoItemsSitemap(Sitemap):
location = "/location/"
def items(self):
return []
def lastmod(self, obj):
return obj.lastmod
class GetLatestLastmodNoneSiteMap(Sitemap):
changefreq = "never"
priority = 0.5
@@ -233,6 +243,10 @@ callable_lastmod_full_sitemap = {
"callable-lastmod": CallableLastmodFullSitemap,
}
callable_lastmod_no_items_sitemap = {
"callable-lastmod": CallableLastmodNoItemsSitemap,
}
urlpatterns = [
path("simple/index.xml", views.index, {"sitemaps": simple_sitemaps}),
path("simple-paged/index.xml", views.index, {"sitemaps": simple_sitemaps_paged}),
@@ -417,6 +431,11 @@ urlpatterns = [
views.sitemap,
{"sitemaps": callable_lastmod_full_sitemap},
),
path(
"callable-lastmod-no-items/index.xml",
views.index,
{"sitemaps": callable_lastmod_no_items_sitemap},
),
path(
"generic-lastmod/index.xml",
views.index,