1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #25989 -- Corrected sitemap's Last-Modified header to use the latest lastmod of all sitemaps.

Previously, the lastmod of the last sitemap was always used.
All sitemaps are required to have a lastmod.
This commit is contained in:
Alexander Rudakov
2015-12-26 21:01:25 +03:00
committed by Tim Graham
parent 104eddbdf6
commit 002a4f72c4
3 changed files with 86 additions and 9 deletions

View File

@@ -1,3 +1,4 @@
from collections import OrderedDict
from datetime import date, datetime
from django.conf.urls import url
@@ -55,6 +56,10 @@ class FixedLastmodMixedSitemap(Sitemap):
return [o1, o2]
class FixedNewerLastmodSitemap(SimpleSitemap):
lastmod = datetime(2013, 4, 20, 5, 0, 0)
class DateSiteMap(SimpleSitemap):
lastmod = date(2013, 3, 13)
@@ -87,6 +92,28 @@ fixed_lastmod__mixed_sitemaps = {
'fixed-lastmod-mixed': FixedLastmodMixedSitemap,
}
sitemaps_lastmod_mixed_ascending = OrderedDict([
('no-lastmod', EmptySitemap),
('lastmod', FixedLastmodSitemap),
])
sitemaps_lastmod_mixed_descending = OrderedDict([
('lastmod', FixedLastmodSitemap),
('no-lastmod', EmptySitemap),
])
sitemaps_lastmod_ascending = OrderedDict([
('date', DateSiteMap),
('datetime', FixedLastmodSitemap),
('datetime-newer', FixedNewerLastmodSitemap),
])
sitemaps_lastmod_descending = OrderedDict([
('datetime-newer', FixedNewerLastmodSitemap),
('datetime', FixedLastmodSitemap),
('date', DateSiteMap),
])
generic_sitemaps = {
'generic': GenericSitemap({'queryset': TestModel.objects.all()}),
}
@@ -123,6 +150,18 @@ urlpatterns = [
url(r'^lastmod/tz-sitemap.xml$', views.sitemap,
{'sitemaps': {'tz-sitemap': TimezoneSiteMap}},
name='django.contrib.sitemaps.views.sitemap'),
url(r'^lastmod-sitemaps/mixed-ascending.xml$', views.sitemap,
{'sitemaps': sitemaps_lastmod_mixed_ascending},
name='django.contrib.sitemaps.views.sitemap'),
url(r'^lastmod-sitemaps/mixed-descending.xml$', views.sitemap,
{'sitemaps': sitemaps_lastmod_mixed_descending},
name='django.contrib.sitemaps.views.sitemap'),
url(r'^lastmod-sitemaps/ascending.xml$', views.sitemap,
{'sitemaps': sitemaps_lastmod_ascending},
name='django.contrib.sitemaps.views.sitemap'),
url(r'^lastmod-sitemaps/descending.xml$', views.sitemap,
{'sitemaps': sitemaps_lastmod_descending},
name='django.contrib.sitemaps.views.sitemap'),
url(r'^generic/sitemap\.xml$', views.sitemap,
{'sitemaps': generic_sitemaps},
name='django.contrib.sitemaps.views.sitemap'),