diff --git a/django/contrib/sitemaps/__init__.py b/django/contrib/sitemaps/__init__.py
index 45b85c81d0b..d31a9d7d2e0 100644
--- a/django/contrib/sitemaps/__init__.py
+++ b/django/contrib/sitemaps/__init__.py
@@ -65,11 +65,12 @@ class Sitemap(object):
urls = []
for item in self.paginator.page(page).object_list:
loc = "http://%s%s" % (current_site.domain, self.__get('location', item))
+ priority = self.__get('priority', item, None)
url_info = {
'location': loc,
'lastmod': self.__get('lastmod', item, None),
'changefreq': self.__get('changefreq', item, None),
- 'priority': str(self.__get('priority', item, ''))
+ 'priority': str(priority is not None and priority or '')
}
urls.append(url_info)
return urls
diff --git a/django/contrib/sitemaps/tests/basic.py b/django/contrib/sitemaps/tests/basic.py
index 695b84a0aec..5dd2aa20101 100644
--- a/django/contrib/sitemaps/tests/basic.py
+++ b/django/contrib/sitemaps/tests/basic.py
@@ -1,5 +1,6 @@
from datetime import date
from django.conf import settings
+from django.contrib.auth.models import User
from django.test import TestCase
from django.utils.formats import localize
from django.utils.translation import activate
@@ -10,6 +11,8 @@ class SitemapTests(TestCase):
def setUp(self):
self.old_USE_L10N = settings.USE_L10N
+ # Create a user that will double as sitemap content
+ User.objects.create_user('testuser', 'test@example.com', 's3krit')
def tearDown(self):
settings.USE_L10N = self.old_USE_L10N
@@ -17,11 +20,11 @@ class SitemapTests(TestCase):
def test_simple_sitemap(self):
"A simple sitemap can be rendered"
# Retrieve the sitemap.
- response = self.client.get('/sitemaps/sitemap.xml')
+ response = self.client.get('/simple/sitemap.xml')
# Check for all the important bits:
self.assertEquals(response.content, """
-http://example.com/ticket14164%snever0.5
+http://example.com/location/%snever0.5
""" % date.today().strftime('%Y-%m-%d'))
@@ -34,6 +37,17 @@ class SitemapTests(TestCase):
# Retrieve the sitemap. Check that priorities
# haven't been rendered in localized format
- response = self.client.get('/sitemaps/sitemap.xml')
+ response = self.client.get('/simple/sitemap.xml')
self.assertContains(response, '0.5')
self.assertContains(response, '%s' % date.today().strftime('%Y-%m-%d'))
+
+ def test_generic_sitemap(self):
+ "A minimal generic sitemap can be rendered"
+ # Retrieve the sitemap.
+ response = self.client.get('/generic/sitemap.xml')
+ # Check for all the important bits:
+ self.assertEquals(response.content, """
+
+http://example.com/users/testuser/
+
+""")
diff --git a/django/contrib/sitemaps/tests/urls.py b/django/contrib/sitemaps/tests/urls.py
index b29b5a6a494..0fb2a7214e7 100644
--- a/django/contrib/sitemaps/tests/urls.py
+++ b/django/contrib/sitemaps/tests/urls.py
@@ -1,20 +1,28 @@
from datetime import datetime
from django.conf.urls.defaults import *
-from django.contrib.sitemaps import Sitemap
+from django.contrib.sitemaps import Sitemap, GenericSitemap
+from django.contrib.auth.models import User
class SimpleSitemap(Sitemap):
changefreq = "never"
priority = 0.5
- location = '/ticket14164'
+ location = '/location/'
lastmod = datetime.now()
def items(self):
return [object()]
-sitemaps = {
+simple_sitemaps = {
'simple': SimpleSitemap,
}
+generic_sitemaps = {
+ 'generic': GenericSitemap({
+ 'queryset': User.objects.all()
+ }),
+}
+
urlpatterns = patterns('django.contrib.sitemaps.views',
- (r'^sitemaps/sitemap\.xml$', 'sitemap', {'sitemaps': sitemaps}),
+ (r'^simple/sitemap\.xml$', 'sitemap', {'sitemaps': simple_sitemaps}),
+ (r'^generic/sitemap\.xml$', 'sitemap', {'sitemaps': generic_sitemaps}),
)