-
diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py
index e068f41..ec7b066 100644
a
|
b
|
PASSWORD_HASHERS = (
|
527 | 529 | 'django.contrib.auth.hashers.CryptPasswordHasher', |
528 | 530 | ) |
529 | 531 | |
| 532 | ######### |
| 533 | # SITES # |
| 534 | ######### |
| 535 | |
| 536 | SITES_SITE_MODEL = 'sites.Site' |
| 537 | |
530 | 538 | ########### |
531 | 539 | # SIGNING # |
532 | 540 | ########### |
-
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
|
16 | 16 | from django.contrib.auth.decorators import login_required |
17 | 17 | from django.contrib.auth.forms import AuthenticationForm, PasswordResetForm, SetPasswordForm, PasswordChangeForm |
18 | 18 | from django.contrib.auth.tokens import default_token_generator |
19 | | from django.contrib.sites.models import get_current_site |
| 19 | from django.contrib.sites import get_current_site |
20 | 20 | |
21 | 21 | |
22 | 22 | @sensitive_post_parameters() |
-
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
|
17 | 17 | from django.contrib.auth.models import User |
18 | 18 | from django.contrib.auth.hashers import UNUSABLE_PASSWORD_PREFIX, identify_hasher |
19 | 19 | from django.contrib.auth.tokens import default_token_generator |
20 | | from django.contrib.sites.models import get_current_site |
| 20 | from django.contrib.sites import get_current_site |
21 | 21 | |
22 | 22 | |
23 | 23 | UNMASKED_DIGITS_TO_SHOW = 6 |
-
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
|
2 | 2 | |
3 | 3 | from django import http |
4 | 4 | from django.contrib.contenttypes.models import ContentType |
5 | | from django.contrib.sites.models import Site, get_current_site |
| 5 | from django.contrib.sites import get_site_model, get_current_site |
6 | 6 | from django.core.exceptions import ObjectDoesNotExist |
7 | 7 | from django.utils.translation import ugettext as _ |
8 | 8 | |
… |
… |
def shortcut(request, content_type_id, object_id):
|
39 | 39 | # relation to the Site object |
40 | 40 | object_domain = None |
41 | 41 | |
| 42 | Site = get_site_model() |
42 | 43 | if Site._meta.installed: |
43 | 44 | opts = obj._meta |
44 | 45 | |
-
diff --git a/django/contrib/comments/feeds.py b/django/contrib/comments/feeds.py
index 2e0d4c3..eee20c0 100644
a
|
b
|
|
1 | 1 | from django.contrib.syndication.views import Feed |
2 | | from django.contrib.sites.models import get_current_site |
| 2 | from django.contrib.sites import get_current_site |
3 | 3 | from django.contrib import comments |
4 | 4 | from django.utils.translation import ugettext as _ |
5 | 5 | |
-
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
|
2 | 2 | from django.contrib.comments.managers import CommentManager |
3 | 3 | from django.contrib.contenttypes import generic |
4 | 4 | from django.contrib.contenttypes.models import ContentType |
5 | | from django.contrib.sites.models import Site |
6 | 5 | from django.core import urlresolvers |
7 | 6 | from django.db import models |
8 | 7 | from django.utils.translation import ugettext_lazy as _ |
… |
… |
class BaseCommentAbstractModel(models.Model):
|
26 | 25 | content_object = generic.GenericForeignKey(ct_field="content_type", fk_field="object_pk") |
27 | 26 | |
28 | 27 | # Metadata about the comment |
29 | | site = models.ForeignKey(Site) |
| 28 | site = models.ForeignKey(settings.SITES_SITE_MODEL) |
30 | 29 | |
31 | 30 | class Meta: |
32 | 31 | abstract = True |
-
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
|
62 | 62 | from django.db.models.base import ModelBase |
63 | 63 | from django.template import Context, loader |
64 | 64 | from django.contrib import comments |
65 | | from django.contrib.sites.models import get_current_site |
| 65 | from django.contrib.sites import get_current_site |
66 | 66 | from django.utils import timezone |
67 | 67 | |
68 | 68 | class AlreadyModerated(Exception): |
-
diff --git a/django/contrib/flatpages/models.py b/django/contrib/flatpages/models.py
index 42bb3ad..60c1831 100644
a
|
b
|
|
1 | 1 | from __future__ import unicode_literals |
2 | 2 | |
3 | 3 | from django.db import models |
4 | | from django.contrib.sites.models import Site |
| 4 | from django.conf import settings |
5 | 5 | from django.core.urlresolvers import get_script_prefix |
6 | 6 | from django.utils.translation import ugettext_lazy as _ |
7 | 7 | from django.utils.encoding import iri_to_uri, python_2_unicode_compatible |
… |
… |
class FlatPage(models.Model):
|
17 | 17 | registration_required = models.BooleanField(_('registration required'), |
18 | 18 | help_text=_("If this is checked, only logged-in users will be able to view the page."), |
19 | 19 | default=False) |
20 | | sites = models.ManyToManyField(Site) |
| 20 | sites = models.ManyToManyField(settings.SITES_SITE_MODEL) |
21 | 21 | |
22 | 22 | class Meta: |
23 | 23 | db_table = 'django_flatpage' |
-
diff --git a/django/contrib/flatpages/views.py b/django/contrib/flatpages/views.py
index 20e930f..34d39cb 100644
a
|
b
|
|
1 | 1 | from django.conf import settings |
2 | 2 | from django.contrib.flatpages.models import FlatPage |
3 | | from django.contrib.sites.models import get_current_site |
| 3 | from django.contrib.sites import get_current_site |
4 | 4 | from django.http import Http404, HttpResponse, HttpResponsePermanentRedirect |
5 | 5 | from django.shortcuts import get_object_or_404 |
6 | 6 | from django.template import loader, RequestContext |
-
diff --git a/django/contrib/flatpages/templatetags/flatpages.py b/django/contrib/flatpages/templatetags/flatpages.py
index a32ac7f..86bfc11 100644
a
|
b
|
|
1 | 1 | from django import template |
2 | 2 | from django.conf import settings |
3 | 3 | from django.contrib.flatpages.models import FlatPage |
4 | | from django.contrib.sites.models import get_current_site |
| 4 | from django.contrib.sites import get_current_site |
5 | 5 | |
6 | 6 | |
7 | 7 | register = template.Library() |
-
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
|
2 | 2 | |
3 | 3 | from django.http import HttpResponse, Http404 |
4 | 4 | from django.template import loader |
5 | | from django.contrib.sites.models import get_current_site |
| 5 | from django.contrib.sites import get_current_site |
6 | 6 | from django.core import urlresolvers |
7 | 7 | from django.core.paginator import EmptyPage, PageNotAnInteger |
8 | 8 | from django.contrib.gis.db.models.fields import GeometryField |
-
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
|
2 | 2 | |
3 | 3 | from django.conf import settings |
4 | 4 | from django.contrib.redirects.models import Redirect |
5 | | from django.contrib.sites.models import get_current_site |
| 5 | from django.contrib.sites import get_current_site |
6 | 6 | from django.core.exceptions import ImproperlyConfigured |
7 | 7 | from django import http |
8 | 8 | |
-
diff --git a/django/contrib/redirects/models.py b/django/contrib/redirects/models.py
index a0376b5..24e30ea 100644
a
|
b
|
|
1 | 1 | from django.db import models |
2 | | from django.contrib.sites.models import Site |
| 2 | from django.conf import settings |
3 | 3 | from django.utils.translation import ugettext_lazy as _ |
4 | 4 | from django.utils.encoding import python_2_unicode_compatible |
5 | 5 | |
6 | 6 | @python_2_unicode_compatible |
7 | 7 | class Redirect(models.Model): |
8 | | site = models.ForeignKey(Site) |
| 8 | site = models.ForeignKey(settings.SITES_SITE_MODEL) |
9 | 9 | old_path = models.CharField(_('redirect from'), max_length=200, db_index=True, |
10 | 10 | help_text=_("This should be an absolute path, excluding the domain name. Example: '/events/search/'.")) |
11 | 11 | new_path = models.CharField(_('redirect to'), max_length=200, blank=True, |
-
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 |
| 1 | from django.contrib.sites import get_site_model |
2 | 2 | from django.core import urlresolvers, paginator |
3 | 3 | from django.core.exceptions import ImproperlyConfigured |
4 | 4 | from django.utils.six.moves.urllib.parse import urlencode |
… |
… |
def ping_google(sitemap_url=None, ping_url=PING_URL):
|
30 | 30 | if sitemap_url is None: |
31 | 31 | raise SitemapNotFound("You didn't provide a sitemap_url, and the sitemap URL couldn't be auto-detected.") |
32 | 32 | |
33 | | from django.contrib.sites.models import Site |
| 33 | Site = get_site_model() |
34 | 34 | current_site = Site.objects.get_current() |
35 | 35 | url = "http://%s%s" % (current_site.domain, sitemap_url) |
36 | 36 | params = urlencode({'sitemap':url}) |
… |
… |
class Sitemap(object):
|
73 | 73 | |
74 | 74 | # Determine domain |
75 | 75 | if site is None: |
| 76 | Site = get_site_model() |
76 | 77 | if Site._meta.installed: |
77 | 78 | try: |
78 | 79 | site = Site.objects.get_current() |
… |
… |
class Sitemap(object):
|
98 | 99 | |
99 | 100 | class FlatPageSitemap(Sitemap): |
100 | 101 | def items(self): |
| 102 | Site = get_site_model() |
101 | 103 | current_site = Site.objects.get_current() |
102 | 104 | return current_site.flatpage_set.filter(registration_required=False) |
103 | 105 | |
-
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
|
12 | 12 | from django.http import Http404 |
13 | 13 | from django.core import urlresolvers |
14 | 14 | from django.contrib.admindocs import utils |
15 | | from django.contrib.sites.models import Site |
16 | 15 | from django.utils.importlib import import_module |
17 | 16 | from django.utils._os import upath |
18 | 17 | from django.utils import six |
… |
… |
def view_index(request):
|
125 | 124 | for settings_mod in settings_modules: |
126 | 125 | urlconf = import_module(settings_mod.ROOT_URLCONF) |
127 | 126 | view_functions = extract_views_from_urlpatterns(urlconf.urlpatterns) |
| 127 | from django.contrib.sites import get_site_model |
| 128 | Site = get_site_model() |
128 | 129 | if Site._meta.installed: |
129 | 130 | site_obj = Site.objects.get(pk=settings_mod.SITE_ID) |
130 | 131 | else: |
-
diff --git a/django/contrib/sitemaps/views.py b/django/contrib/sitemaps/views.py
index 95bc7ea..72fc1a3 100644
a
|
b
|
|
1 | 1 | import warnings |
2 | 2 | from functools import wraps |
3 | 3 | |
4 | | from django.contrib.sites.models import get_current_site |
| 4 | from django.contrib.sites import get_current_site |
5 | 5 | from django.core import urlresolvers |
6 | 6 | from django.core.paginator import EmptyPage, PageNotAnInteger |
7 | 7 | from django.http import Http404 |
-
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
|
3 | 3 | from calendar import timegm |
4 | 4 | |
5 | 5 | from django.conf import settings |
6 | | from django.contrib.sites.models import get_current_site |
| 6 | from django.contrib.sites import get_current_site |
7 | 7 | from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist |
8 | 8 | from django.http import HttpResponse, Http404 |
9 | 9 | from django.template import loader, TemplateDoesNotExist, RequestContext |
-
diff --git a/django/contrib/sites/__init__.py b/django/contrib/sites/__init__.py
index e69de29..2474488 100644
a
|
b
|
|
| 1 | from django.conf import settings |
| 2 | from django.core.exceptions import ImproperlyConfigured |
| 3 | |
| 4 | |
| 5 | def 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 | |
| 21 | def 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 |
-
diff --git a/django/contrib/sites/models.py b/django/contrib/sites/models.py
index bbd85ed..8af74fb 100644
a
|
b
|
|
1 | 1 | from __future__ import unicode_literals |
2 | 2 | |
3 | 3 | import string |
| 4 | import warnings |
4 | 5 | |
| 6 | from django.conf import settings |
5 | 7 | from django.db import models |
6 | 8 | from django.db.models.signals import pre_save, pre_delete |
7 | 9 | from django.utils.translation import ugettext_lazy as _ |
8 | 10 | from django.utils.encoding import python_2_unicode_compatible |
9 | 11 | from django.core.exceptions import ValidationError |
| 12 | from django.contrib import sites |
10 | 13 | |
11 | 14 | |
12 | 15 | SITE_CACHE = {} |
… |
… |
class SiteManager(models.Manager):
|
35 | 38 | project's settings. The ``Site`` object is cached the first |
36 | 39 | time it's retrieved from the database. |
37 | 40 | """ |
38 | | from django.conf import settings |
39 | 41 | try: |
40 | 42 | sid = settings.SITE_ID |
41 | 43 | except AttributeError: |
… |
… |
class SiteManager(models.Manager):
|
55 | 57 | |
56 | 58 | |
57 | 59 | @python_2_unicode_compatible |
58 | | class Site(models.Model): |
59 | | |
60 | | domain = models.CharField(_('domain name'), max_length=100, |
| 60 | class AbstractSite(models.Model): |
| 61 | domain = models.CharField(_('domain name'), max_length=100, db_index=True, |
61 | 62 | validators=[_simple_domain_name_validator]) |
62 | | name = models.CharField(_('display name'), max_length=50) |
| 63 | |
63 | 64 | objects = SiteManager() |
64 | 65 | |
65 | 66 | class Meta: |
| 67 | abstract = True |
66 | 68 | db_table = 'django_site' |
67 | 69 | verbose_name = _('site') |
68 | 70 | verbose_name_plural = _('sites') |
… |
… |
class Site(models.Model):
|
72 | 74 | return self.domain |
73 | 75 | |
74 | 76 | |
| 77 | class Site(AbstractSite): |
| 78 | name = models.CharField(_('display name'), max_length=50) |
| 79 | |
| 80 | class Meta(AbstractSite.Meta): |
| 81 | swappable = 'SITES_SITE_MODEL' |
| 82 | |
| 83 | |
75 | 84 | @python_2_unicode_compatible |
76 | 85 | class RequestSite(object): |
77 | 86 | """ |
… |
… |
class RequestSite(object):
|
95 | 104 | |
96 | 105 | |
97 | 106 | def 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) |
107 | 109 | |
108 | 110 | |
109 | 111 | def clear_site_cache(sender, **kwargs): |
… |
… |
def clear_site_cache(sender, **kwargs):
|
115 | 117 | del SITE_CACHE[instance.pk] |
116 | 118 | except KeyError: |
117 | 119 | pass |
118 | | pre_save.connect(clear_site_cache, sender=Site) |
119 | | pre_delete.connect(clear_site_cache, sender=Site) |
| 120 | pre_save.connect(clear_site_cache, sender=settings.SITES_SITE_MODEL) |
| 121 | pre_delete.connect(clear_site_cache, sender=settings.SITES_SITE_MODEL) |
-
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
|
3 | 3 | from django.db import models |
4 | 4 | from django.contrib.contenttypes.models import ContentType |
5 | 5 | from django.contrib.contenttypes.views import shortcut |
6 | | from django.contrib.sites.models import Site, get_current_site |
| 6 | from django.contrib.sites import get_site_model, get_current_site |
7 | 7 | from django.http import HttpRequest, Http404 |
8 | 8 | from django.test import TestCase |
9 | 9 | from django.test.utils import override_settings |
… |
… |
from django.utils.http import urlquote
|
11 | 11 | from django.utils import six |
12 | 12 | from django.utils.encoding import python_2_unicode_compatible |
13 | 13 | |
| 14 | Site = get_site_model() |
| 15 | |
14 | 16 | |
15 | 17 | class ConcreteModel(models.Model): |
16 | 18 | name = models.CharField(max_length=10) |
-
diff --git a/django/contrib/sites/tests.py b/django/contrib/sites/tests.py
index 6bfbfd7..89d8f46 100644
a
|
b
|
|
1 | 1 | from __future__ import unicode_literals |
2 | 2 | |
3 | 3 | from django.conf import settings |
4 | | from django.contrib.sites.models import Site, RequestSite, get_current_site |
| 4 | from django.contrib.sites import get_site_model, get_current_site |
| 5 | from django.contrib.sites.models import RequestSite |
5 | 6 | from django.core.exceptions import ObjectDoesNotExist, ValidationError |
6 | 7 | from django.http import HttpRequest |
7 | 8 | from django.test import TestCase |
8 | 9 | from django.test.utils import override_settings |
9 | 10 | |
| 11 | Site = get_site_model() |
| 12 | |
10 | 13 | |
11 | 14 | class SitesFrameworkTests(TestCase): |
12 | 15 | |