Ticket #10235: sitemaps_requestsite.diff

File sitemaps_requestsite.diff, 3.3 KB (added by Arthur Koziel, 16 years ago)
  • django/contrib/sitemaps/__init__.py

    diff --git a/django/contrib/sitemaps/__init__.py b/django/contrib/sitemaps/__init__.py
    index f877317..2599b74 100644
    a b def ping_google(sitemap_url=None, ping_url=PING_URL):  
    2727    if sitemap_url is None:
    2828        raise SitemapNotFound("You didn't provide a sitemap_url, and the sitemap URL couldn't be auto-detected.")
    2929
    30     from django.contrib.sites.models import Site
    31     current_site = Site.objects.get_current()
     30    from django.contrib.sites.models import Site, RequestSite
     31    if Site._meta.installed:
     32        current_site = Site.objects.get_current()
     33    else:
     34        current_site = RequestSite(request)
    3235    url = "http://%s%s" % (current_site.domain, sitemap_url)
    3336    params = urllib.urlencode({'sitemap':url})
    3437    urllib.urlopen("%s?%s" % (ping_url, params))
    class Sitemap(object):  
    5962        return self._paginator
    6063    paginator = property(_get_paginator)
    6164
    62     def get_urls(self, page=1):
    63         from django.contrib.sites.models import Site
    64         current_site = Site.objects.get_current()
     65    def get_urls(self, request, page=1):
     66        from django.contrib.sites.models import Site, RequestSite
     67        if Site._meta.installed:
     68            current_site = Site.objects.get_current()
     69        else:
     70            current_site = RequestSite(request)
    6571        urls = []
    6672        for item in self.paginator.page(page).object_list:
    6773            loc = "http://%s%s" % (current_site.domain, self.__get('location', item))
    class Sitemap(object):  
    7682
    7783class FlatPageSitemap(Sitemap):
    7884    def items(self):
    79         from django.contrib.sites.models import Site
    80         current_site = Site.objects.get_current()
     85        from django.contrib.sites.models import Site, RequestSite
     86        if Site._meta.installed:
     87            current_site = Site.objects.get_current()
     88        else:
     89            current_site = RequestSite(request)
    8190        return current_site.flatpage_set.all()
    8291
    8392class GenericSitemap(Sitemap):
  • django/contrib/sitemaps/views.py

    diff --git a/django/contrib/sitemaps/views.py b/django/contrib/sitemaps/views.py
    index 7a5fe38..48ef374 100644
    a b  
    11from django.http import HttpResponse, Http404
    22from django.template import loader
    3 from django.contrib.sites.models import Site
     3from django.contrib.sites.models import Site, RequestSite
    44from django.core import urlresolvers
    55from django.utils.encoding import smart_str
    66from django.core.paginator import EmptyPage, PageNotAnInteger
    77
    88def index(request, sitemaps):
    9     current_site = Site.objects.get_current()
     9    if Site._meta.installed:
     10        current_site = Site.objects.get_current()
     11    else:
     12        current_site = RequestSite(request)
    1013    sites = []
    1114    protocol = request.is_secure() and 'https' or 'http'
    1215    for section, site in sitemaps.items():
    def sitemap(request, sitemaps, section=None):  
    3437    for site in maps:
    3538        try:
    3639            if callable(site):
    37                 urls.extend(site().get_urls(page))
     40                urls.extend(site().get_urls(request, page))
    3841            else:
    39                 urls.extend(site.get_urls(page))
     42                urls.extend(site.get_urls(request, page))
    4043        except EmptyPage:
    4144            raise Http404("Page %s empty" % page)
    4245        except PageNotAnInteger:
Back to Top