Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #11358: Don't include private flatpages in sitemap. Thanks dbur…

…ke and mlavin.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13734 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 59129038524972fc423193d49ca6cd096189ec58 1 parent 364583b
@kmtracey kmtracey authored
View
2  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
View
24 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 @@ def test_generic_sitemap(self):
<url><loc>http://example.com/users/testuser/</loc></url>
</urlset>
""")
+
+ 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, '<loc>http://example.com%s</loc>' % public.url)
+ # Private flatpage should not be in the sitemap
+ self.assertNotContains(response, '<loc>http://example.com%s</loc>' % private.url)
+
View
7 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 @@ def items(self):
}),
}
+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}),
)
View
4 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 <django.contrib.flatpages>` defined for the current
- :setting:`SITE_ID` (see the
+ publicly visible :mod:`flatpages <django.contrib.flatpages>`
+ defined for the current :setting:`SITE_ID` (see the
:mod:`sites documentation <django.contrib.sites>`) and
creates an entry in the sitemap. These entries include only the
:attr:`~Sitemap.location` attribute -- not :attr:`~Sitemap.lastmod`,
Please sign in to comment.
Something went wrong with that request. Please try again.