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):
|
| 27 | 27 | if sitemap_url is None: |
| 28 | 28 | raise SitemapNotFound("You didn't provide a sitemap_url, and the sitemap URL couldn't be auto-detected.") |
| 29 | 29 | |
| 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) |
| 32 | 35 | url = "http://%s%s" % (current_site.domain, sitemap_url) |
| 33 | 36 | params = urllib.urlencode({'sitemap':url}) |
| 34 | 37 | urllib.urlopen("%s?%s" % (ping_url, params)) |
| … |
… |
class Sitemap(object):
|
| 59 | 62 | return self._paginator |
| 60 | 63 | paginator = property(_get_paginator) |
| 61 | 64 | |
| 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) |
| 65 | 71 | urls = [] |
| 66 | 72 | for item in self.paginator.page(page).object_list: |
| 67 | 73 | loc = "http://%s%s" % (current_site.domain, self.__get('location', item)) |
| … |
… |
class Sitemap(object):
|
| 76 | 82 | |
| 77 | 83 | class FlatPageSitemap(Sitemap): |
| 78 | 84 | 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) |
| 81 | 90 | return current_site.flatpage_set.all() |
| 82 | 91 | |
| 83 | 92 | class GenericSitemap(Sitemap): |
diff --git a/django/contrib/sitemaps/views.py b/django/contrib/sitemaps/views.py
index 7a5fe38..48ef374 100644
|
a
|
b
|
|
| 1 | 1 | from django.http import HttpResponse, Http404 |
| 2 | 2 | from django.template import loader |
| 3 | | from django.contrib.sites.models import Site |
| | 3 | from django.contrib.sites.models import Site, RequestSite |
| 4 | 4 | from django.core import urlresolvers |
| 5 | 5 | from django.utils.encoding import smart_str |
| 6 | 6 | from django.core.paginator import EmptyPage, PageNotAnInteger |
| 7 | 7 | |
| 8 | 8 | def 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) |
| 10 | 13 | sites = [] |
| 11 | 14 | protocol = request.is_secure() and 'https' or 'http' |
| 12 | 15 | for section, site in sitemaps.items(): |
| … |
… |
def sitemap(request, sitemaps, section=None):
|
| 34 | 37 | for site in maps: |
| 35 | 38 | try: |
| 36 | 39 | if callable(site): |
| 37 | | urls.extend(site().get_urls(page)) |
| | 40 | urls.extend(site().get_urls(request, page)) |
| 38 | 41 | else: |
| 39 | | urls.extend(site.get_urls(page)) |
| | 42 | urls.extend(site.get_urls(request, page)) |
| 40 | 43 | except EmptyPage: |
| 41 | 44 | raise Http404("Page %s empty" % page) |
| 42 | 45 | except PageNotAnInteger: |