Ticket #10608: django_requestsite.patch

File django_requestsite.patch, 6.8 KB (added by hvendelbo, 6 years ago)
  • django/contrib/auth/forms.py

    a b  
    11from django.contrib.auth.models import User
    22from django.contrib.auth import authenticate
    33from django.contrib.auth.tokens import default_token_generator
    4 from django.contrib.sites.models import Site
     4from django.contrib.sites.models import Site, RequestSite
    55from django.template import Context, loader
    66from django import forms
    77from django.utils.translation import ugettext_lazy as _
    class PasswordResetForm(forms.Form): 
    116116        from django.core.mail import send_mail
    117117        for user in self.users_cache:
    118118            if not domain_override:
    119                 current_site = Site.objects.get_current()
     119                if Site._meta.installed:
     120                    current_site = Site.objects.get_current()
     121                else:
     122                    current_site = RequestSite(request)
    120123                site_name = current_site.name
    121124                domain = current_site.domain
    122125            else:
  • django/contrib/comments/feeds.py

    a b  
    11from django.conf import settings
    22from django.contrib.syndication.feeds import Feed
    3 from django.contrib.sites.models import Site
     3from django.contrib.sites.models import Site, RequestSite
    44from django.contrib import comments
    55
    66class LatestCommentFeed(Feed):
    class LatestCommentFeed(Feed): 
    88
    99    def title(self):
    1010        if not hasattr(self, '_site'):
    11             self._site = Site.objects.get_current()
     11            if Site._meta.installed:
     12                self._site = Site.objects.get_current()
     13            else:
     14                self._site = RequestSite(request)
    1215        return u"%s comments" % self._site.name
    1316
    1417    def link(self):
    1518        if not hasattr(self, '_site'):
    16             self._site = Site.objects.get_current()
     19            if Site._meta.installed:
     20                self._site = Site.objects.get_current()
     21            else:
     22                self._site = RequestSite(request)
    1723        return "http://%s/" % (self._site.domain)
    1824
    1925    def description(self):
    2026        if not hasattr(self, '_site'):
    21             self._site = Site.objects.get_current()
     27            if Site._meta.installed:
     28                self._site = Site.objects.get_current()
     29            else:
     30                self._site = RequestSite(request)
    2231        return u"Latest comments on %s" % self._site.name
    2332
    2433    def items(self):
  • django/contrib/contenttypes/views.py

    a b  
    11from django import http
    22from django.contrib.contenttypes.models import ContentType
    3 from django.contrib.sites.models import Site
     3from django.contrib.sites.models import Site, RequestSite
    44from django.core.exceptions import ObjectDoesNotExist
    55
    66def shortcut(request, content_type_id, object_id):
    def shortcut(request, content_type_id, object_id): 
    5454    # Fall back to the current site (if possible).
    5555    if object_domain is None:
    5656        try:
    57             object_domain = Site.objects.get_current().domain
     57            if Site._meta.installed:
     58                object_domain = Site.objects.get_current().domain
     59            else:
     60                object_domain = RequestSite(request).domain
    5861        except Site.DoesNotExist:
    5962            pass
    6063
  • django/contrib/gis/sitemaps/views.py

    a b  
    11from django.http import HttpResponse, Http404
    22from django.template import loader
    33from django.contrib.gis.db.backend import SpatialBackend
    4 from django.contrib.sites.models import Site
     4from django.contrib.sites.models import Site, RequestSite
    55from django.core import urlresolvers
    66from django.core.paginator import EmptyPage, PageNotAnInteger
    77from django.db.models import get_model
    def index(request, sitemaps): 
    1515    This view generates a sitemap index that uses the proper view
    1616    for resolving geographic section sitemap URLs.
    1717    """
    18     current_site = Site.objects.get_current()
     18    if Site._meta.installed:
     19        current_site = Site.objects.get_current()
     20    else:
     21        current_site = RequestSite(request)
    1922    sites = []
    2023    protocol = request.is_secure() and 'https' or 'http'
    2124    for section, site in sitemaps.items():
  • django/contrib/sitemaps/__init__.py

    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): 
    6063    paginator = property(_get_paginator)
    6164
    6265    def get_urls(self, page=1):
    63         from django.contrib.sites.models import Site
    64         current_site = Site.objects.get_current()
     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

    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():
Back to Top