Ticket #10909: 10909.diff

File 10909.diff, 1.9 KB (added by Chris Beaven, 15 years ago)
  • django/contrib/sitemaps/__init__.py

     
    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()
    32     url = "http://%s%s" % (current_site.domain, sitemap_url)
    33     params = urllib.urlencode({'sitemap':url})
     30    if '://' not in sitemap_url:
     31        from django.contrib.sites.models import Site
     32        current_site = Site.objects.get_current()
     33        sitemap_url = "http://%s%s" % (current_site.domain, sitemap_url)
     34    params = urllib.urlencode({'sitemap': sitemap_url})
    3435    urllib.urlopen("%s?%s" % (ping_url, params))
    3536
    3637class Sitemap(object):
     
    6061    paginator = property(_get_paginator)
    6162
    6263    def get_urls(self, page=1):
    63         from django.contrib.sites.models import Site
    64         current_site = Site.objects.get_current()
    6564        urls = []
    6665        for item in self.paginator.page(page).object_list:
    67             loc = "http://%s%s" % (current_site.domain, self.__get('location', item))
     66            loc = "http://%s%s" % (self.get_domain(),
     67                                   self.__get('location', item))
    6868            url_info = {
    6969                'location':   loc,
    7070                'lastmod':    self.__get('lastmod', item, None),
     
    7474            urls.append(url_info)
    7575        return urls
    7676
     77    def get_domain(self):
     78        # This method can be overridden to avoid the requirement of the sites
     79        # contrib application.
     80        from django.contrib.sites.models import Site
     81        return Site.objects.get_current().domain
     82
    7783class FlatPageSitemap(Sitemap):
    7884    def items(self):
    7985        from django.contrib.sites.models import Site
Back to Top