Ticket #17802: pass-the-request-down-to-the-sitemap-callable.diff

File pass-the-request-down-to-the-sitemap-callable.diff, 1.9 KB (added by rm_, 13 years ago)

Diffed against r17606

  • django/contrib/sitemaps/views.py

     
    1313    sites = []
    1414    for section, site in sitemaps.items():
    1515        if callable(site):
    16             site = site()
     16            site = site(request=request)
    1717        protocol = req_protocol if site.protocol is None else site.protocol
    1818        sitemap_url = urlresolvers.reverse(
    1919                sitemap_url_name, kwargs={'section': section})
     
    4242    for site in maps:
    4343        try:
    4444            if callable(site):
    45                 site = site()
     45                site = site(request=request)
    4646            urls.extend(site.get_urls(page=page, site=req_site,
    4747                                      protocol=req_protocol))
    4848        except EmptyPage:
  • django/contrib/sitemaps/__init__.py

     
    4040    # http://sitemaps.org/protocol.php#index.
    4141    limit = 50000
    4242
     43    def __init__(self, request=None):
     44        self.request = request
     45
    4346    # If protocol is None, the URLs in the sitemap will use the protocol
    4447    # with which the sitemap was requested.
    4548    protocol = None
     
    104107    priority = None
    105108    changefreq = None
    106109
    107     def __init__(self, info_dict, priority=None, changefreq=None):
     110    def __init__(self, info_dict, priority=None, changefreq=None, request=None):
    108111        self.queryset = info_dict['queryset']
    109112        self.date_field = info_dict.get('date_field', None)
    110113        self.priority = priority
    111114        self.changefreq = changefreq
     115        self.request = request
    112116
    113117    def items(self):
    114118        # Make sure to return a clone; we don't want premature evaluation.
Back to Top