Ticket #2713: 2713_2.diff

File 2713_2.diff, 3.3 KB (added by Michael, 6 years ago)

Updated patch + unittest

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

    diff --git a/django/contrib/sitemaps/tests/basic.py b/django/contrib/sitemaps/tests/basic.py
    index 775e0d9..bee5676 100644
    a b class SitemapTests(TestCase): 
    182182            return isinstance(url['item'], User)
    183183        item_in_url_info = all(map(is_user, user_sitemap.get_urls()))
    184184        self.assertTrue(item_in_url_info)
     185
     186    def test_cached_sitemap_index(self):
     187        "A cached sitemap index can be rendered"
     188        # Retrieve the sitemap.
     189        response = self.client.get('/cached/index.xml')
     190        # Check for all the important bits:
     191        self.assertEqual(response.content, """<?xml version="1.0" encoding="UTF-8"?>
     192<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
     193<sitemap><loc>%s/cached/sitemap-simple.xml</loc></sitemap>
     194</sitemapindex>
     195""" % self.base_url)
  • django/contrib/sitemaps/tests/urls.py

    diff --git a/django/contrib/sitemaps/tests/urls.py b/django/contrib/sitemaps/tests/urls.py
    index c264f94..2ebad20 100644
    a b  
    11from datetime import datetime
    2 from django.conf.urls import patterns
     2from django.conf.urls import patterns, url
    33from django.contrib.sitemaps import Sitemap, GenericSitemap, FlatPageSitemap
    44from django.contrib.auth.models import User
     5from django.views.decorators.cache import cache_page
     6from django.contrib.sitemaps import views
    57
    68class SimpleSitemap(Sitemap):
    79    changefreq = "never"
    urlpatterns = patterns('django.contrib.sitemaps.views', 
    3436    (r'^simple/custom-sitemap\.xml$', 'sitemap', {'sitemaps': simple_sitemaps, 'template_name': 'custom_sitemap.xml'}),
    3537    (r'^generic/sitemap\.xml$', 'sitemap', {'sitemaps': generic_sitemaps}),
    3638    (r'^flatpages/sitemap\.xml$', 'sitemap', {'sitemaps': flatpage_sitemaps}),
     39    (r'^cached/index\.xml$', cache_page(views.index, 1), {
     40        'sitemaps': simple_sitemaps,
     41        'sitemap_url_name': 'sitemaps.views.sitemap'
     42        }),
     43    url(r'^cached/sitemap-(?P<section>.+)\.xml',
     44        cache_page(views.sitemap, 1), {
     45            'sitemaps': simple_sitemaps
     46        },
     47        name='sitemaps.views.sitemap')
    3748)
  • django/contrib/sitemaps/views.py

    diff --git a/django/contrib/sitemaps/views.py b/django/contrib/sitemaps/views.py
    index d82146c..8a3c041 100644
    a b from django.template.response import TemplateResponse 
    66from django.contrib.sites.models import get_current_site
    77
    88def index(request, sitemaps,
    9         template_name='sitemap_index.xml', mimetype='application/xml'):
     9        template_name='sitemap_index.xml', mimetype='application/xml',
     10        sitemap_url_name='django.contrib.sitemaps.views.sitemap'):
    1011    current_site = get_current_site(request)
    1112    sites = []
    1213    protocol = request.is_secure() and 'https' or 'http'
    def index(request, sitemaps, 
    1617            pages = site().paginator.num_pages
    1718        else:
    1819            pages = site.paginator.num_pages
    19         sitemap_url = urlresolvers.reverse('django.contrib.sitemaps.views.sitemap', kwargs={'section': section})
     20        sitemap_url = urlresolvers.reverse(sitemap_url_name, kwargs={'section': section})
    2021        sites.append('%s://%s%s' % (protocol, current_site.domain, sitemap_url))
    2122        if pages > 1:
    2223            for page in range(2, pages+1):
Back to Top