Ticket #11358: 11358_with_test.patch

File 11358_with_test.patch, 3.7 KB (added by mlavin, 5 years ago)

Patch against [13714] to add tests and doc change

  • django/contrib/sitemaps/tests/basic.py

     
    11from datetime import date
    22from django.conf import settings
    33from django.contrib.auth.models import User
     4from django.contrib.flatpages.models import FlatPage
    45from django.test import TestCase
    56from django.utils.formats import localize
    67from django.utils.translation import activate
     
    5152<url><loc>http://example.com/users/testuser/</loc></url>
    5253</urlset>
    5354""")
     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
  • django/contrib/sitemaps/tests/urls.py

     
    11from datetime import datetime
    22from django.conf.urls.defaults import *
    3 from django.contrib.sitemaps import Sitemap, GenericSitemap
     3from django.contrib.sitemaps import Sitemap, GenericSitemap, FlatPageSitemap
    44from django.contrib.auth.models import User
    55
    66class SimpleSitemap(Sitemap):
     
    2222    }),
    2323}
    2424
     25flatpage_sitemaps = {
     26    'flatpages': FlatPageSitemap,
     27}
     28
    2529urlpatterns = patterns('django.contrib.sitemaps.views',
    2630    (r'^simple/sitemap\.xml$', 'sitemap', {'sitemaps': simple_sitemaps}),
    2731    (r'^generic/sitemap\.xml$', 'sitemap', {'sitemaps': generic_sitemaps}),
     32    (r'^flatpages/sitemap\.xml$', 'sitemap', {'sitemaps': flatpage_sitemaps}),
    2833)
  • django/contrib/sitemaps/__init__.py

     
    7979    def items(self):
    8080        from django.contrib.sites.models import Site
    8181        current_site = Site.objects.get_current()
    82         return current_site.flatpage_set.all()
     82        return current_site.flatpage_set.filter(registration_required=False)
    8383
    8484class GenericSitemap(Sitemap):
    8585    priority = None
  • docs/ref/contrib/sitemaps.txt

     
    215215.. class:: FlatPageSitemap
    216216
    217217    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
    220220    :mod:`sites documentation <django.contrib.sites>`) and
    221221    creates an entry in the sitemap. These entries include only the
    222222    :attr:`~Sitemap.location` attribute -- not :attr:`~Sitemap.lastmod`,
Back to Top