Ticket #10235: sitemaps_requestsite_2.diff

File sitemaps_requestsite_2.diff, 2.7 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..295077a 100644
    a b  
    11from django.core import urlresolvers, paginator
     2from django.contrib.sites.models import get_current
    23import urllib
    34
    45PING_URL = "http://www.google.com/webmasters/tools/ping"
    class 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()
     64        current_site = get_current(self.request)
    6565        urls = []
    6666        for item in self.paginator.page(page).object_list:
    6767            loc = "http://%s%s" % (current_site.domain, self.__get('location', item))
  • django/contrib/sitemaps/views.py

    diff --git a/django/contrib/sitemaps/views.py b/django/contrib/sitemaps/views.py
    index 7a5fe38..8d7255a 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 get_current
    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    current_site = get_current(request)
    1010    sites = []
    1111    protocol = request.is_secure() and 'https' or 'http'
    1212    for section, site in sitemaps.items():
     13        site.request = request
    1314        if callable(site):
    1415            pages = site().paginator.num_pages
    1516        else:
    def sitemap(request, sitemaps, section=None):  
    3233        maps = sitemaps.values()
    3334    page = request.GET.get("p", 1)
    3435    for site in maps:
     36        site.request = request
    3537        try:
    3638            if callable(site):
    3739                urls.extend(site().get_urls(page))
  • django/contrib/sites/models.py

    diff --git a/django/contrib/sites/models.py b/django/contrib/sites/models.py
    index c8b395e..5b8e64f 100644
    a b class RequestSite(object):  
    6969
    7070    def delete(self):
    7171        raise NotImplementedError('RequestSite cannot be deleted.')
     72
     73def 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
Back to Top