diff --git a/django/contrib/sitemaps/__init__.py b/django/contrib/sitemaps/__init__.py
index f877317..295077a 100644
a
|
b
|
|
1 | 1 | from django.core import urlresolvers, paginator |
| 2 | from django.contrib.sites.models import get_current |
2 | 3 | import urllib |
3 | 4 | |
4 | 5 | PING_URL = "http://www.google.com/webmasters/tools/ping" |
… |
… |
class Sitemap(object):
|
60 | 61 | paginator = property(_get_paginator) |
61 | 62 | |
62 | 63 | def get_urls(self, page=1): |
63 | | from django.contrib.sites.models import Site |
64 | | current_site = Site.objects.get_current() |
| 64 | current_site = get_current(self.request) |
65 | 65 | urls = [] |
66 | 66 | for item in self.paginator.page(page).object_list: |
67 | 67 | loc = "http://%s%s" % (current_site.domain, self.__get('location', item)) |
diff --git a/django/contrib/sitemaps/views.py b/django/contrib/sitemaps/views.py
index 7a5fe38..8d7255a 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 get_current |
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 | current_site = get_current(request) |
10 | 10 | sites = [] |
11 | 11 | protocol = request.is_secure() and 'https' or 'http' |
12 | 12 | for section, site in sitemaps.items(): |
| 13 | site.request = request |
13 | 14 | if callable(site): |
14 | 15 | pages = site().paginator.num_pages |
15 | 16 | else: |
… |
… |
def sitemap(request, sitemaps, section=None):
|
32 | 33 | maps = sitemaps.values() |
33 | 34 | page = request.GET.get("p", 1) |
34 | 35 | for site in maps: |
| 36 | site.request = request |
35 | 37 | try: |
36 | 38 | if callable(site): |
37 | 39 | urls.extend(site().get_urls(page)) |
diff --git a/django/contrib/sites/models.py b/django/contrib/sites/models.py
index c8b395e..5b8e64f 100644
a
|
b
|
class RequestSite(object):
|
69 | 69 | |
70 | 70 | def delete(self): |
71 | 71 | raise NotImplementedError('RequestSite cannot be deleted.') |
| 72 | |
| 73 | def get_current(request): |
| 74 | """ |
| 75 | Checks if contrib.sites is installed and returns either the current |
| 76 | ``Site`` object from the database or the current ``RequestSite`` object |
| 77 | from the request. |
| 78 | """ |
| 79 | if Site._meta.installed: |
| 80 | current_site = Site.objects.get_current() |
| 81 | else: |
| 82 | current_site = RequestSite(request) |
| 83 | return current_site |