diff --git a/django/contrib/sitemaps/__init__.py b/django/contrib/sitemaps/__init__.py index d31a9d7d2e..eaa7f85de9 100644 --- a/django/contrib/sitemaps/__init__.py +++ b/django/contrib/sitemaps/__init__.py @@ -79,7 +79,7 @@ class FlatPageSitemap(Sitemap): def items(self): from django.contrib.sites.models import Site current_site = Site.objects.get_current() - return current_site.flatpage_set.all() + return current_site.flatpage_set.filter(registration_required=False) class GenericSitemap(Sitemap): priority = None diff --git a/django/contrib/sitemaps/tests/basic.py b/django/contrib/sitemaps/tests/basic.py index 5dd2aa2010..ad04db258f 100644 --- a/django/contrib/sitemaps/tests/basic.py +++ b/django/contrib/sitemaps/tests/basic.py @@ -1,6 +1,7 @@ from datetime import date from django.conf import settings from django.contrib.auth.models import User +from django.contrib.flatpages.models import FlatPage from django.test import TestCase from django.utils.formats import localize from django.utils.translation import activate @@ -51,3 +52,26 @@ class SitemapTests(TestCase): http://example.com/users/testuser/ """) + + def test_flatpage_sitemap(self): + "Basic FlatPage sitemap test" + public = FlatPage.objects.create( + url=u'/public/', + title=u'Public Page', + enable_comments=True, + registration_required=False, + ) + public.sites.add(settings.SITE_ID) + private = FlatPage.objects.create( + url=u'/private/', + title=u'Public Page', + enable_comments=True, + registration_required=True + ) + private.sites.add(settings.SITE_ID) + response = self.client.get('/flatpages/sitemap.xml') + # Public flatpage should be in the sitemap + self.assertContains(response, 'http://example.com%s' % public.url) + # Private flatpage should not be in the sitemap + self.assertNotContains(response, 'http://example.com%s' % private.url) + diff --git a/django/contrib/sitemaps/tests/urls.py b/django/contrib/sitemaps/tests/urls.py index 0fb2a7214e..6cdba36b02 100644 --- a/django/contrib/sitemaps/tests/urls.py +++ b/django/contrib/sitemaps/tests/urls.py @@ -1,6 +1,6 @@ from datetime import datetime from django.conf.urls.defaults import * -from django.contrib.sitemaps import Sitemap, GenericSitemap +from django.contrib.sitemaps import Sitemap, GenericSitemap, FlatPageSitemap from django.contrib.auth.models import User class SimpleSitemap(Sitemap): @@ -22,7 +22,12 @@ generic_sitemaps = { }), } +flatpage_sitemaps = { + 'flatpages': FlatPageSitemap, +} + urlpatterns = patterns('django.contrib.sitemaps.views', (r'^simple/sitemap\.xml$', 'sitemap', {'sitemaps': simple_sitemaps}), (r'^generic/sitemap\.xml$', 'sitemap', {'sitemaps': generic_sitemaps}), + (r'^flatpages/sitemap\.xml$', 'sitemap', {'sitemaps': flatpage_sitemaps}), ) diff --git a/docs/ref/contrib/sitemaps.txt b/docs/ref/contrib/sitemaps.txt index 113d4d3531..7a66cbe9a9 100644 --- a/docs/ref/contrib/sitemaps.txt +++ b/docs/ref/contrib/sitemaps.txt @@ -215,8 +215,8 @@ The sitemap framework provides a couple convenience classes for common cases: .. class:: FlatPageSitemap The :class:`django.contrib.sitemaps.FlatPageSitemap` class looks at all - :mod:`flatpages ` defined for the current - :setting:`SITE_ID` (see the + publicly visible :mod:`flatpages ` + defined for the current :setting:`SITE_ID` (see the :mod:`sites documentation `) and creates an entry in the sitemap. These entries include only the :attr:`~Sitemap.location` attribute -- not :attr:`~Sitemap.lastmod`,