Ticket #14433: 14433.diff

File 14433.diff, 4.8 KB (added by Gabriel Hurley, 14 years ago)

Restores thread-safety to contrib.sitemaps

  • django/contrib/gis/sitemaps/georss.py

     
    3636            else:
    3737                self.locations.append(section)
    3838 
    39     def get_urls(self, page=1):
     39    def get_urls(self, page=1, site=None):
    4040        """
    4141        This method is overrridden so the appropriate `geo_format` attribute
    4242        is placed on each URL element.
    4343        """
    44         urls = Sitemap.get_urls(self, page=page)
     44        urls = Sitemap.get_urls(self, page=page, site=site)
    4545        for url in urls: url['geo_format'] = 'georss'
    4646        return urls
    4747
  • django/contrib/gis/sitemaps/kml.py

     
    4040                raise TypeError('KML Sources must be a model or a 3-tuple.')
    4141        return kml_sources
    4242
    43     def get_urls(self, page=1):
     43    def get_urls(self, page=1, site=None):
    4444        """
    4545        This method is overrridden so the appropriate `geo_format` attribute
    4646        is placed on each URL element.
    4747        """
    48         urls = Sitemap.get_urls(self, page=page)
     48        urls = Sitemap.get_urls(self, page=page, site=site)
    4949        for url in urls: url['geo_format'] = self.geo_format
    5050        return urls
    5151
  • django/contrib/gis/sitemaps/views.py

     
    4646        maps = sitemaps.values()
    4747
    4848    page = request.GET.get("p", 1)
     49    current_site = get_current_site(request)
    4950    for site in maps:
    5051        try:
    5152            if callable(site):
    52                 urls.extend(site().get_urls(page))
     53                urls.extend(site().get_urls(page, current_site))
    5354            else:
    54                 urls.extend(site.get_urls(page))
     55                urls.extend(site.get_urls(page, current_site))
    5556        except EmptyPage:
    5657            raise Http404("Page %s empty" % page)
    5758        except PageNotAnInteger:
  • django/contrib/sitemaps/__init__.py

     
    1 from django.contrib.sites.models import get_current_site
     1from django.contrib.sites.models import Site, get_current_site
    22from django.core import urlresolvers, paginator
    33import urllib
    44
     
    6060        return self._paginator
    6161    paginator = property(_get_paginator)
    6262
    63     def get_urls(self, page=1):
    64         current_site = get_current_site(self.request)
     63    def get_urls(self, page=1, site=None):
     64        if site is None:
     65            try:
     66                site = Site.objects.get_current()
     67            except Site.DoesNotExist:
     68                raise ImproperlyConfigured("In order to use Sitemaps you must either use the sites framework or pass in a Site or RequestSite object in your view code.")
    6569        urls = []
    6670        for item in self.paginator.page(page).object_list:
    67             loc = "http://%s%s" % (current_site.domain, self.__get('location', item))
     71            loc = "http://%s%s" % (site.domain, self.__get('location', item))
    6872            priority = self.__get('priority', item, None)
    6973            url_info = {
    7074                'location':   loc,
     
    7781
    7882class FlatPageSitemap(Sitemap):
    7983    def items(self):
    80         current_site = get_current_site(self.request)
    81         if hasattr(current_site, "flatpage_set"):
    82             return current_site.flatpage_set.filter(registration_required=False)
    83         else:
    84             return ()
     84        current_site = Site.objects.get_current()
     85        return current_site.flatpage_set.filter(registration_required=False)
    8586
    8687class GenericSitemap(Sitemap):
    8788    priority = None
  • django/contrib/sitemaps/views.py

     
    3232    else:
    3333        maps = sitemaps.values()
    3434    page = request.GET.get("p", 1)
     35    current_site = get_current_site(request)
    3536    for site in maps:
    36         site.request = request
    3737        try:
    3838            if callable(site):
    39                 urls.extend(site().get_urls(page))
     39                urls.extend(site().get_urls(page, current_site))
    4040            else:
    41                 urls.extend(site.get_urls(page))
     41                urls.extend(site.get_urls(page, current_site))
    4242        except EmptyPage:
    4343            raise Http404("Page %s empty" % page)
    4444        except PageNotAnInteger:
Back to Top