Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Karen Tracey authored September 10, 2010
2  django/contrib/sitemaps/__init__.py
@@ -79,7 +79,7 @@ class FlatPageSitemap(Sitemap):
79 79
     def items(self):
80 80
         from django.contrib.sites.models import Site
81 81
         current_site = Site.objects.get_current()
82  
-        return current_site.flatpage_set.all()
  82
+        return current_site.flatpage_set.filter(registration_required=False)
83 83
 
84 84
 class GenericSitemap(Sitemap):
85 85
     priority = None
24  django/contrib/sitemaps/tests/basic.py
... ...
@@ -1,6 +1,7 @@
1 1
 from datetime import date
2 2
 from django.conf import settings
3 3
 from django.contrib.auth.models import User
  4
+from django.contrib.flatpages.models import FlatPage
4 5
 from django.test import TestCase
5 6
 from django.utils.formats import localize
6 7
 from django.utils.translation import activate
@@ -51,3 +52,26 @@ def test_generic_sitemap(self):
51 52
 <url><loc>http://example.com/users/testuser/</loc></url>
52 53
 </urlset>
53 54
 """)
  55
+
  56
+    def test_flatpage_sitemap(self):
  57
+        "Basic FlatPage sitemap test"
  58
+        public = FlatPage.objects.create(
  59
+            url=u'/public/',
  60
+            title=u'Public Page',
  61
+            enable_comments=True,
  62
+            registration_required=False,
  63
+        )
  64
+        public.sites.add(settings.SITE_ID)
  65
+        private = FlatPage.objects.create(
  66
+            url=u'/private/',
  67
+            title=u'Public Page',
  68
+            enable_comments=True,
  69
+            registration_required=True    
  70
+        )
  71
+        private.sites.add(settings.SITE_ID)
  72
+        response = self.client.get('/flatpages/sitemap.xml')
  73
+        # Public flatpage should be in the sitemap
  74
+        self.assertContains(response, '<loc>http://example.com%s</loc>' % public.url)
  75
+        # Private flatpage should not be in the sitemap
  76
+        self.assertNotContains(response, '<loc>http://example.com%s</loc>' % private.url)
  77
+
7  django/contrib/sitemaps/tests/urls.py
... ...
@@ -1,6 +1,6 @@
1 1
 from datetime import datetime
2 2
 from django.conf.urls.defaults import *
3  
-from django.contrib.sitemaps import Sitemap, GenericSitemap
  3
+from django.contrib.sitemaps import Sitemap, GenericSitemap, FlatPageSitemap
4 4
 from django.contrib.auth.models import User
5 5
 
6 6
 class SimpleSitemap(Sitemap):
@@ -22,7 +22,12 @@ def items(self):
22 22
     }),
23 23
 }
24 24
 
  25
+flatpage_sitemaps = {
  26
+    'flatpages': FlatPageSitemap,
  27
+}
  28
+
25 29
 urlpatterns = patterns('django.contrib.sitemaps.views',
26 30
     (r'^simple/sitemap\.xml$', 'sitemap', {'sitemaps': simple_sitemaps}),
27 31
     (r'^generic/sitemap\.xml$', 'sitemap', {'sitemaps': generic_sitemaps}),
  32
+    (r'^flatpages/sitemap\.xml$', 'sitemap', {'sitemaps': flatpage_sitemaps}),
28 33
 )
4  docs/ref/contrib/sitemaps.txt
@@ -215,8 +215,8 @@ The sitemap framework provides a couple convenience classes for common cases:
215 215
 .. class:: FlatPageSitemap
216 216
 
217 217
     The :class:`django.contrib.sitemaps.FlatPageSitemap` class looks at all
218  
-    :mod:`flatpages <django.contrib.flatpages>` defined for the current
219  
-    :setting:`SITE_ID` (see the
  218
+    publicly visible :mod:`flatpages <django.contrib.flatpages>`
  219
+    defined for the current :setting:`SITE_ID` (see the
220 220
     :mod:`sites documentation <django.contrib.sites>`) and
221 221
     creates an entry in the sitemap. These entries include only the
222 222
     :attr:`~Sitemap.location` attribute -- not :attr:`~Sitemap.lastmod`,

0 notes on commit 5912903

Please sign in to comment.
Something went wrong with that request. Please try again.