Fixed #21112 -- Make sure sitemaps with no lastmod date work correctly.

Thanks to Matthias Kestenholz for the report and patch.
This commit is contained in:
Simon Charette 2013-09-17 10:21:11 -04:00
parent 9400142132
commit f5f662fa5f
4 changed files with 20 additions and 1 deletions

View File

@ -338,6 +338,7 @@ answer newbie questions, and generally made Django that much better:
Niall Kelly <duke.sam.vimes@gmail.com>
Ryan Kelly <ryan@rfk.id.au>
Thomas Kerpe <thomas@kerpe.net>
Matthias Kestenholz <mk@406.ch>
Wiley Kestner <wiley.kestner@gmail.com>
Ossama M. Khayat <okhayat@yahoo.com>
Ben Khoo <khoobks@westnet.com.au>

View File

@ -102,7 +102,7 @@ class Sitemap(object):
'priority': str(priority if priority is not None else ''),
}
urls.append(url_info)
if all_items_lastmod:
if all_items_lastmod and latest_lastmod:
self.latest_lastmod = latest_lastmod
return urls

View File

@ -166,3 +166,7 @@ class HTTPSitemapTests(SitemapTestsBase):
response = self.client.get('/simple/sitemap.xml')
self.assertEqual(response['X-Robots-Tag'], 'noindex, noodp, noarchive')
def test_empty_sitemap(self):
response = self.client.get('/empty/sitemap.xml')
self.assertEqual(response.status_code, 200)

View File

@ -16,6 +16,15 @@ class SimpleSitemap(Sitemap):
return [object()]
class EmptySitemap(Sitemap):
changefreq = "never"
priority = 0.5
location = '/location/'
def items(self):
return []
class FixedLastmodSitemap(SimpleSitemap):
lastmod = datetime(2013, 3, 13, 10, 0, 0)
@ -37,6 +46,10 @@ simple_sitemaps = {
'simple': SimpleSitemap,
}
empty_sitemaps = {
'empty': EmptySitemap,
}
fixed_lastmod_sitemaps = {
'fixed-lastmod': FixedLastmodSitemap,
}
@ -62,6 +75,7 @@ urlpatterns = patterns('django.contrib.sitemaps.views',
(r'^simple/sitemap\.xml$', 'sitemap', {'sitemaps': simple_sitemaps}),
(r'^simple/custom-sitemap\.xml$', 'sitemap',
{'sitemaps': simple_sitemaps, 'template_name': 'custom_sitemap.xml'}),
(r'^empty/sitemap\.xml$', 'sitemap', {'sitemaps': empty_sitemaps}),
(r'^lastmod/sitemap\.xml$', 'sitemap', {'sitemaps': fixed_lastmod_sitemaps}),
(r'^lastmod-mixed/sitemap\.xml$', 'sitemap', {'sitemaps': fixed_lastmod__mixed_sitemaps}),
(r'^generic/sitemap\.xml$', 'sitemap', {'sitemaps': generic_sitemaps}),