Ticket #22779: #22779-swappable_sites.diff

File #22779-swappable_sites.diff, 17.6 KB (added by German M. Bravo, 10 years ago)
  • django/conf/global_settings.py

    diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py
    index e068f41..ec7b066 100644
    a b PASSWORD_HASHERS = (  
    527529    'django.contrib.auth.hashers.CryptPasswordHasher',
    528530)
    529531
     532#########
     533# SITES #
     534#########
     535
     536SITES_SITE_MODEL = 'sites.Site'
     537
    530538###########
    531539# SIGNING #
    532540###########
  • django/contrib/auth/views.py

    diff --git a/django/contrib/auth/views.py b/django/contrib/auth/views.py
    index c55f243..86d1e0f 100644
    a b from django.contrib.auth import REDIRECT_FIELD_NAME, login as auth_login, logout  
    1616from django.contrib.auth.decorators import login_required
    1717from django.contrib.auth.forms import AuthenticationForm, PasswordResetForm, SetPasswordForm, PasswordChangeForm
    1818from django.contrib.auth.tokens import default_token_generator
    19 from django.contrib.sites.models import get_current_site
     19from django.contrib.sites import get_current_site
    2020
    2121
    2222@sensitive_post_parameters()
  • django/contrib/auth/forms.py

    diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py
    index 081d9e5..16f4bf2 100644
    a b from django.contrib.auth import authenticate, get_user_model  
    1717from django.contrib.auth.models import User
    1818from django.contrib.auth.hashers import UNUSABLE_PASSWORD_PREFIX, identify_hasher
    1919from django.contrib.auth.tokens import default_token_generator
    20 from django.contrib.sites.models import get_current_site
     20from django.contrib.sites import get_current_site
    2121
    2222
    2323UNMASKED_DIGITS_TO_SHOW = 6
  • django/contrib/contenttypes/views.py

    diff --git a/django/contrib/contenttypes/views.py b/django/contrib/contenttypes/views.py
    index 6d4a71928..f829da9 100644
    a b from __future__ import unicode_literals  
    22
    33from django import http
    44from django.contrib.contenttypes.models import ContentType
    5 from django.contrib.sites.models import Site, get_current_site
     5from django.contrib.sites import get_site_model, get_current_site
    66from django.core.exceptions import ObjectDoesNotExist
    77from django.utils.translation import ugettext as _
    88
    def shortcut(request, content_type_id, object_id):  
    3939    # relation to the Site object
    4040    object_domain = None
    4141
     42    Site = get_site_model()
    4243    if Site._meta.installed:
    4344        opts = obj._meta
    4445
  • django/contrib/comments/feeds.py

    diff --git a/django/contrib/comments/feeds.py b/django/contrib/comments/feeds.py
    index 2e0d4c3..eee20c0 100644
    a b  
    11from django.contrib.syndication.views import Feed
    2 from django.contrib.sites.models import get_current_site
     2from django.contrib.sites import get_current_site
    33from django.contrib import comments
    44from django.utils.translation import ugettext as _
    55
  • django/contrib/comments/models.py

    diff --git a/django/contrib/comments/models.py b/django/contrib/comments/models.py
    index bc4d932..9bbcb7a 100644
    a b from django.conf import settings  
    22from django.contrib.comments.managers import CommentManager
    33from django.contrib.contenttypes import generic
    44from django.contrib.contenttypes.models import ContentType
    5 from django.contrib.sites.models import Site
    65from django.core import urlresolvers
    76from django.db import models
    87from django.utils.translation import ugettext_lazy as _
    class BaseCommentAbstractModel(models.Model):  
    2625    content_object = generic.GenericForeignKey(ct_field="content_type", fk_field="object_pk")
    2726
    2827    # Metadata about the comment
    29     site = models.ForeignKey(Site)
     28    site = models.ForeignKey(settings.SITES_SITE_MODEL)
    3029
    3130    class Meta:
    3231        abstract = True
  • django/contrib/comments/moderation.py

    diff --git a/django/contrib/comments/moderation.py b/django/contrib/comments/moderation.py
    index 6648aeb..8fa0c14 100644
    a b from django.contrib.comments import signals  
    6262from django.db.models.base import ModelBase
    6363from django.template import Context, loader
    6464from django.contrib import comments
    65 from django.contrib.sites.models import get_current_site
     65from django.contrib.sites import get_current_site
    6666from django.utils import timezone
    6767
    6868class AlreadyModerated(Exception):
  • django/contrib/flatpages/models.py

    diff --git a/django/contrib/flatpages/models.py b/django/contrib/flatpages/models.py
    index 42bb3ad..60c1831 100644
    a b  
    11from __future__ import unicode_literals
    22
    33from django.db import models
    4 from django.contrib.sites.models import Site
     4from django.conf import settings
    55from django.core.urlresolvers import get_script_prefix
    66from django.utils.translation import ugettext_lazy as _
    77from django.utils.encoding import iri_to_uri, python_2_unicode_compatible
    class FlatPage(models.Model):  
    1717    registration_required = models.BooleanField(_('registration required'),
    1818        help_text=_("If this is checked, only logged-in users will be able to view the page."),
    1919        default=False)
    20     sites = models.ManyToManyField(Site)
     20    sites = models.ManyToManyField(settings.SITES_SITE_MODEL)
    2121
    2222    class Meta:
    2323        db_table = 'django_flatpage'
  • django/contrib/flatpages/views.py

    diff --git a/django/contrib/flatpages/views.py b/django/contrib/flatpages/views.py
    index 20e930f..34d39cb 100644
    a b  
    11from django.conf import settings
    22from django.contrib.flatpages.models import FlatPage
    3 from django.contrib.sites.models import get_current_site
     3from django.contrib.sites import get_current_site
    44from django.http import Http404, HttpResponse, HttpResponsePermanentRedirect
    55from django.shortcuts import get_object_or_404
    66from django.template import loader, RequestContext
  • django/contrib/flatpages/templatetags/flatpages.py

    diff --git a/django/contrib/flatpages/templatetags/flatpages.py b/django/contrib/flatpages/templatetags/flatpages.py
    index a32ac7f..86bfc11 100644
    a b  
    11from django import template
    22from django.conf import settings
    33from django.contrib.flatpages.models import FlatPage
    4 from django.contrib.sites.models import get_current_site
     4from django.contrib.sites import get_current_site
    55
    66
    77register = template.Library()
  • django/contrib/gis/sitemaps/views.py

    diff --git a/django/contrib/gis/sitemaps/views.py b/django/contrib/gis/sitemaps/views.py
    index 9682c12..1857a76 100644
    a b from __future__ import unicode_literals  
    22
    33from django.http import HttpResponse, Http404
    44from django.template import loader
    5 from django.contrib.sites.models import get_current_site
     5from django.contrib.sites import get_current_site
    66from django.core import urlresolvers
    77from django.core.paginator import EmptyPage, PageNotAnInteger
    88from django.contrib.gis.db.models.fields import GeometryField
  • django/contrib/redirects/middleware.py

    diff --git a/django/contrib/redirects/middleware.py b/django/contrib/redirects/middleware.py
    index 03c9d97..7a57bc5 100644
    a b from __future__ import unicode_literals  
    22
    33from django.conf import settings
    44from django.contrib.redirects.models import Redirect
    5 from django.contrib.sites.models import get_current_site
     5from django.contrib.sites import get_current_site
    66from django.core.exceptions import ImproperlyConfigured
    77from django import http
    88
  • django/contrib/redirects/models.py

    diff --git a/django/contrib/redirects/models.py b/django/contrib/redirects/models.py
    index a0376b5..24e30ea 100644
    a b  
    11from django.db import models
    2 from django.contrib.sites.models import Site
     2from django.conf import settings
    33from django.utils.translation import ugettext_lazy as _
    44from django.utils.encoding import python_2_unicode_compatible
    55
    66@python_2_unicode_compatible
    77class Redirect(models.Model):
    8     site = models.ForeignKey(Site)
     8    site = models.ForeignKey(settings.SITES_SITE_MODEL)
    99    old_path = models.CharField(_('redirect from'), max_length=200, db_index=True,
    1010        help_text=_("This should be an absolute path, excluding the domain name. Example: '/events/search/'."))
    1111    new_path = models.CharField(_('redirect to'), max_length=200, blank=True,
  • django/contrib/sitemaps/__init__.py

    diff --git a/django/contrib/sitemaps/__init__.py b/django/contrib/sitemaps/__init__.py
    index 72c1932..d9af017 100644
    a b  
    1 from django.contrib.sites.models import Site
     1from django.contrib.sites import get_site_model
    22from django.core import urlresolvers, paginator
    33from django.core.exceptions import ImproperlyConfigured
    44from django.utils.six.moves.urllib.parse import urlencode
    def ping_google(sitemap_url=None, ping_url=PING_URL):  
    3030    if sitemap_url is None:
    3131        raise SitemapNotFound("You didn't provide a sitemap_url, and the sitemap URL couldn't be auto-detected.")
    3232
    33     from django.contrib.sites.models import Site
     33    Site = get_site_model()
    3434    current_site = Site.objects.get_current()
    3535    url = "http://%s%s" % (current_site.domain, sitemap_url)
    3636    params = urlencode({'sitemap':url})
    class Sitemap(object):  
    7373
    7474        # Determine domain
    7575        if site is None:
     76            Site = get_site_model()
    7677            if Site._meta.installed:
    7778                try:
    7879                    site = Site.objects.get_current()
    class Sitemap(object):  
    9899
    99100class FlatPageSitemap(Sitemap):
    100101    def items(self):
     102        Site = get_site_model()
    101103        current_site = Site.objects.get_current()
    102104        return current_site.flatpage_set.filter(registration_required=False)
    103105
  • django/contrib/admindocs/views.py

    diff --git a/django/contrib/admindocs/views.py b/django/contrib/admindocs/views.py
    index b3faf06..b5308ac 100644
    a b from django.core.exceptions import ImproperlyConfigured, ViewDoesNotExist  
    1212from django.http import Http404
    1313from django.core import urlresolvers
    1414from django.contrib.admindocs import utils
    15 from django.contrib.sites.models import Site
    1615from django.utils.importlib import import_module
    1716from django.utils._os import upath
    1817from django.utils import six
    def view_index(request):  
    125124    for settings_mod in settings_modules:
    126125        urlconf = import_module(settings_mod.ROOT_URLCONF)
    127126        view_functions = extract_views_from_urlpatterns(urlconf.urlpatterns)
     127        from django.contrib.sites import get_site_model
     128        Site = get_site_model()
    128129        if Site._meta.installed:
    129130            site_obj = Site.objects.get(pk=settings_mod.SITE_ID)
    130131        else:
  • django/contrib/sitemaps/views.py

    diff --git a/django/contrib/sitemaps/views.py b/django/contrib/sitemaps/views.py
    index 95bc7ea..72fc1a3 100644
    a b  
    11import warnings
    22from functools import wraps
    33
    4 from django.contrib.sites.models import get_current_site
     4from django.contrib.sites import get_current_site
    55from django.core import urlresolvers
    66from django.core.paginator import EmptyPage, PageNotAnInteger
    77from django.http import Http404
  • django/contrib/syndication/views.py

    diff --git a/django/contrib/syndication/views.py b/django/contrib/syndication/views.py
    index 3bfba3b..9537cda 100644
    a b from __future__ import unicode_literals  
    33from calendar import timegm
    44
    55from django.conf import settings
    6 from django.contrib.sites.models import get_current_site
     6from django.contrib.sites import get_current_site
    77from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist
    88from django.http import HttpResponse, Http404
    99from django.template import loader, TemplateDoesNotExist, RequestContext
  • django/contrib/sites/__init__.py

    diff --git a/django/contrib/sites/__init__.py b/django/contrib/sites/__init__.py
    index e69de29..2474488 100644
    a b  
     1from django.conf import settings
     2from django.core.exceptions import ImproperlyConfigured
     3
     4
     5def get_site_model():
     6    """
     7    Returns the Site model that is active in this project.
     8    """
     9    from django.db.models import get_model
     10
     11    try:
     12        app_label, model_name = settings.SITES_SITE_MODEL.split('.')
     13    except (ValueError, AttributeError):
     14        raise ImproperlyConfigured("SITES_SITE_MODEL must be of the form 'app_label.model_name'")
     15    site_model = get_model(app_label, model_name)
     16    if site_model is None:
     17        raise ImproperlyConfigured("SITES_SITE_MODEL refers to model '%s' that has not been installed" % settings.SITES_SITE_MODEL)
     18    return site_model
     19
     20
     21def get_current_site(request):
     22    """
     23    Checks if contrib.sites is installed and returns either the current
     24    ``Site`` object or a ``RequestSite`` object based on the request.
     25    """
     26    from django.contrib.sites.models import RequestSite
     27    Site = get_site_model()
     28    if Site._meta.installed:
     29        current_site = Site.objects.get_current()
     30    elif RequestSite:
     31        current_site = RequestSite(request)
     32    return current_site
  • django/contrib/sites/models.py

    diff --git a/django/contrib/sites/models.py b/django/contrib/sites/models.py
    index bbd85ed..8af74fb 100644
    a b  
    11from __future__ import unicode_literals
    22
    33import string
     4import warnings
    45
     6from django.conf import settings
    57from django.db import models
    68from django.db.models.signals import pre_save, pre_delete
    79from django.utils.translation import ugettext_lazy as _
    810from django.utils.encoding import python_2_unicode_compatible
    911from django.core.exceptions import ValidationError
     12from django.contrib import sites
    1013
    1114
    1215SITE_CACHE = {}
    class SiteManager(models.Manager):  
    3538        project's settings. The ``Site`` object is cached the first
    3639        time it's retrieved from the database.
    3740        """
    38         from django.conf import settings
    3941        try:
    4042            sid = settings.SITE_ID
    4143        except AttributeError:
    class SiteManager(models.Manager):  
    5557
    5658
    5759@python_2_unicode_compatible
    58 class Site(models.Model):
    59 
    60     domain = models.CharField(_('domain name'), max_length=100,
     60class AbstractSite(models.Model):
     61    domain = models.CharField(_('domain name'), max_length=100, db_index=True,
    6162        validators=[_simple_domain_name_validator])
    62     name = models.CharField(_('display name'), max_length=50)
     63
    6364    objects = SiteManager()
    6465
    6566    class Meta:
     67        abstract = True
    6668        db_table = 'django_site'
    6769        verbose_name = _('site')
    6870        verbose_name_plural = _('sites')
    class Site(models.Model):  
    7274        return self.domain
    7375
    7476
     77class Site(AbstractSite):
     78    name = models.CharField(_('display name'), max_length=50)
     79
     80    class Meta(AbstractSite.Meta):
     81        swappable = 'SITES_SITE_MODEL'
     82
     83
    7584@python_2_unicode_compatible
    7685class RequestSite(object):
    7786    """
    class RequestSite(object):  
    95104
    96105
    97106def get_current_site(request):
    98     """
    99     Checks if contrib.sites is installed and returns either the current
    100     ``Site`` object or a ``RequestSite`` object based on the request.
    101     """
    102     if Site._meta.installed:
    103         current_site = Site.objects.get_current()
    104     else:
    105         current_site = RequestSite(request)
    106     return current_site
     107    warnings.warn("django.contrib.sites.models.get_current_site is deprecated, use django.contrib.sites.get_current_site instead.", PendingDeprecationWarning)
     108    return sites.get_current_site(request)
    107109
    108110
    109111def clear_site_cache(sender, **kwargs):
    def clear_site_cache(sender, **kwargs):  
    115117        del SITE_CACHE[instance.pk]
    116118    except KeyError:
    117119        pass
    118 pre_save.connect(clear_site_cache, sender=Site)
    119 pre_delete.connect(clear_site_cache, sender=Site)
     120pre_save.connect(clear_site_cache, sender=settings.SITES_SITE_MODEL)
     121pre_delete.connect(clear_site_cache, sender=settings.SITES_SITE_MODEL)
  • django/contrib/contenttypes/tests.py

    diff --git a/django/contrib/contenttypes/tests.py b/django/contrib/contenttypes/tests.py
    index f300294..dc12aee 100644
    a b from __future__ import unicode_literals  
    33from django.db import models
    44from django.contrib.contenttypes.models import ContentType
    55from django.contrib.contenttypes.views import shortcut
    6 from django.contrib.sites.models import Site, get_current_site
     6from django.contrib.sites import get_site_model, get_current_site
    77from django.http import HttpRequest, Http404
    88from django.test import TestCase
    99from django.test.utils import override_settings
    from django.utils.http import urlquote  
    1111from django.utils import six
    1212from django.utils.encoding import python_2_unicode_compatible
    1313
     14Site = get_site_model()
     15
    1416
    1517class ConcreteModel(models.Model):
    1618    name = models.CharField(max_length=10)
  • django/contrib/sites/tests.py

    diff --git a/django/contrib/sites/tests.py b/django/contrib/sites/tests.py
    index 6bfbfd7..89d8f46 100644
    a b  
    11from __future__ import unicode_literals
    22
    33from django.conf import settings
    4 from django.contrib.sites.models import Site, RequestSite, get_current_site
     4from django.contrib.sites import get_site_model, get_current_site
     5from django.contrib.sites.models import RequestSite
    56from django.core.exceptions import ObjectDoesNotExist, ValidationError
    67from django.http import HttpRequest
    78from django.test import TestCase
    89from django.test.utils import override_settings
    910
     11Site = get_site_model()
     12
    1013
    1114class SitesFrameworkTests(TestCase):
    1215
Back to Top