Author: kmtracey
Date: 2010-09-10 18:30:46 -0500 (Fri, 10 Sep 2010)
New Revision: 13734

Modified:
   django/trunk/django/contrib/sitemaps/__init__.py
   django/trunk/django/contrib/sitemaps/tests/basic.py
   django/trunk/django/contrib/sitemaps/tests/urls.py
   django/trunk/docs/ref/contrib/sitemaps.txt
Log:
Fixed #11358: Don't include private flatpages in sitemap. Thanks dburke and 
mlavin.


Modified: django/trunk/django/contrib/sitemaps/__init__.py
===================================================================
--- django/trunk/django/contrib/sitemaps/__init__.py    2010-09-10 23:11:24 UTC 
(rev 13733)
+++ django/trunk/django/contrib/sitemaps/__init__.py    2010-09-10 23:30:46 UTC 
(rev 13734)
@@ -79,7 +79,7 @@
     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

Modified: django/trunk/django/contrib/sitemaps/tests/basic.py
===================================================================
--- django/trunk/django/contrib/sitemaps/tests/basic.py 2010-09-10 23:11:24 UTC 
(rev 13733)
+++ django/trunk/django/contrib/sitemaps/tests/basic.py 2010-09-10 23:30:46 UTC 
(rev 13734)
@@ -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 @@
 <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)
+

Modified: django/trunk/django/contrib/sitemaps/tests/urls.py
===================================================================
--- django/trunk/django/contrib/sitemaps/tests/urls.py  2010-09-10 23:11:24 UTC 
(rev 13733)
+++ django/trunk/django/contrib/sitemaps/tests/urls.py  2010-09-10 23:30:46 UTC 
(rev 13734)
@@ -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 @@
     }),
 }
 
+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}),
 )

Modified: django/trunk/docs/ref/contrib/sitemaps.txt
===================================================================
--- django/trunk/docs/ref/contrib/sitemaps.txt  2010-09-10 23:11:24 UTC (rev 
13733)
+++ django/trunk/docs/ref/contrib/sitemaps.txt  2010-09-10 23:30:46 UTC (rev 
13734)
@@ -215,8 +215,8 @@
 .. 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`,

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to