summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2012-09-28 20:10:22 +0200
committerClaude Paroz <claude@2xlibre.net>2012-09-28 20:33:05 +0200
commit6c2faaceb0482267cec19da0ff432984028f9d0c (patch)
tree5d62d1d3e058282c5bc7aa4c416c3b458f10d76c /django
parent1cd6e04cd4f768bcd4385b75de433d497d938f82 (diff)
Made more extensive use of get_current_site
Refs #15089
Diffstat (limited to 'django')
-rw-r--r--django/contrib/comments/moderation.py4
-rw-r--r--django/contrib/contenttypes/tests.py5
-rw-r--r--django/contrib/flatpages/templatetags/flatpages.py7
-rw-r--r--django/contrib/redirects/middleware.py6
-rw-r--r--django/views/decorators/cache.py2
5 files changed, 15 insertions, 9 deletions
diff --git a/django/contrib/comments/moderation.py b/django/contrib/comments/moderation.py
index 9b206a5bad..6c56d7a8a5 100644
--- a/django/contrib/comments/moderation.py
+++ b/django/contrib/comments/moderation.py
@@ -62,7 +62,7 @@ from django.contrib.comments import signals
from django.db.models.base import ModelBase
from django.template import Context, loader
from django.contrib import comments
-from django.contrib.sites.models import Site
+from django.contrib.sites.models import get_current_site
from django.utils import timezone
class AlreadyModerated(Exception):
@@ -240,7 +240,7 @@ class CommentModerator(object):
t = loader.get_template('comments/comment_notification_email.txt')
c = Context({ 'comment': comment,
'content_object': content_object })
- subject = '[%s] New comment posted on "%s"' % (Site.objects.get_current().name,
+ subject = '[%s] New comment posted on "%s"' % (get_current_site(request).name,
content_object)
message = t.render(c)
send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, recipient_list, fail_silently=True)
diff --git a/django/contrib/contenttypes/tests.py b/django/contrib/contenttypes/tests.py
index 2f92a34581..10311fae92 100644
--- a/django/contrib/contenttypes/tests.py
+++ b/django/contrib/contenttypes/tests.py
@@ -3,7 +3,7 @@ from __future__ import unicode_literals
from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.views import shortcut
-from django.contrib.sites.models import Site
+from django.contrib.sites.models import Site, get_current_site
from django.http import HttpRequest, Http404
from django.test import TestCase
from django.utils.http import urlquote
@@ -219,9 +219,8 @@ class ContentTypesTests(TestCase):
obj = FooWithUrl.objects.create(name="john")
if Site._meta.installed:
- current_site = Site.objects.get_current()
response = shortcut(request, user_ct.id, obj.id)
- self.assertEqual("http://%s/users/john/" % current_site.domain,
+ self.assertEqual("http://%s/users/john/" % get_current_site(request).domain,
response._headers.get("location")[1])
Site._meta.installed = False
diff --git a/django/contrib/flatpages/templatetags/flatpages.py b/django/contrib/flatpages/templatetags/flatpages.py
index 702d968145..a32ac7f490 100644
--- a/django/contrib/flatpages/templatetags/flatpages.py
+++ b/django/contrib/flatpages/templatetags/flatpages.py
@@ -1,6 +1,7 @@
from django import template
from django.conf import settings
from django.contrib.flatpages.models import FlatPage
+from django.contrib.sites.models import get_current_site
register = template.Library()
@@ -19,7 +20,11 @@ class FlatpageNode(template.Node):
self.user = None
def render(self, context):
- flatpages = FlatPage.objects.filter(sites__id=settings.SITE_ID)
+ if 'request' in context:
+ site_pk = get_current_site(context['request']).pk
+ else:
+ site_pk = settings.SITE_ID
+ flatpages = FlatPage.objects.filter(sites__id=site_pk)
# If a prefix was specified, add a filter
if self.starts_with:
flatpages = flatpages.filter(
diff --git a/django/contrib/redirects/middleware.py b/django/contrib/redirects/middleware.py
index 8998c2ce3e..927220d44d 100644
--- a/django/contrib/redirects/middleware.py
+++ b/django/contrib/redirects/middleware.py
@@ -1,4 +1,5 @@
from django.contrib.redirects.models import Redirect
+from django.contrib.sites.models import get_current_site
from django import http
from django.conf import settings
@@ -7,14 +8,15 @@ class RedirectFallbackMiddleware(object):
if response.status_code != 404:
return response # No need to check for a redirect for non-404 responses.
path = request.get_full_path()
+ current_site = get_current_site(request)
try:
- r = Redirect.objects.get(site__id__exact=settings.SITE_ID, old_path=path)
+ r = Redirect.objects.get(site__id__exact=current_site.id, old_path=path)
except Redirect.DoesNotExist:
r = None
if r is None and settings.APPEND_SLASH:
# Try removing the trailing slash.
try:
- r = Redirect.objects.get(site__id__exact=settings.SITE_ID,
+ r = Redirect.objects.get(site__id__exact=current_site.id,
old_path=path[:path.rfind('/')]+path[path.rfind('/')+1:])
except Redirect.DoesNotExist:
pass
diff --git a/django/views/decorators/cache.py b/django/views/decorators/cache.py
index ac8b3752d7..06925c1f4a 100644
--- a/django/views/decorators/cache.py
+++ b/django/views/decorators/cache.py
@@ -12,7 +12,7 @@ def cache_page(*args, **kwargs):
The cache is keyed by the URL and some data from the headers.
Additionally there is the key prefix that is used to distinguish different
cache areas in a multi-site setup. You could use the
- sites.get_current().domain, for example, as that is unique across a Django
+ sites.get_current_site().domain, for example, as that is unique across a Django
project.
Additionally, all headers from the response's Vary header will be taken