summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Charette <charette.s@gmail.com>2013-09-17 10:21:11 -0400
committerSimon Charette <charette.s@gmail.com>2013-09-17 10:21:11 -0400
commitf5f662fa5f4efd1f0fdd7901ed58c34f384af532 (patch)
treee1f93896e3136c6f45b51d8bf563f85716b10c4d
parent94001421321bd8808c4027a72aa32a1eef005764 (diff)
Fixed #21112 -- Make sure sitemaps with no lastmod date work correctly.
Thanks to Matthias Kestenholz for the report and patch.
-rw-r--r--AUTHORS1
-rw-r--r--django/contrib/sitemaps/__init__.py2
-rw-r--r--django/contrib/sitemaps/tests/test_http.py4
-rw-r--r--django/contrib/sitemaps/tests/urls/http.py14
4 files changed, 20 insertions, 1 deletions
diff --git a/AUTHORS b/AUTHORS
index a2a0eb979a..7e620f89a6 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -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>
diff --git a/django/contrib/sitemaps/__init__.py b/django/contrib/sitemaps/__init__.py
index 996e719865..fd71276be7 100644
--- a/django/contrib/sitemaps/__init__.py
+++ b/django/contrib/sitemaps/__init__.py
@@ -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
diff --git a/django/contrib/sitemaps/tests/test_http.py b/django/contrib/sitemaps/tests/test_http.py
index c870b442de..6d6862e0a6 100644
--- a/django/contrib/sitemaps/tests/test_http.py
+++ b/django/contrib/sitemaps/tests/test_http.py
@@ -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)
diff --git a/django/contrib/sitemaps/tests/urls/http.py b/django/contrib/sitemaps/tests/urls/http.py
index 6721d72b81..2cadb23deb 100644
--- a/django/contrib/sitemaps/tests/urls/http.py
+++ b/django/contrib/sitemaps/tests/urls/http.py
@@ -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}),