Commit 6c2faace authored by Claude Paroz's avatar Claude Paroz
Browse files

Made more extensive use of get_current_site

Refs #15089
parent 1cd6e04c
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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)
+2 −3
Original line number Diff line number Diff line
@@ -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
+6 −1
Original line number Diff line number Diff line
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(
+4 −2
Original line number Diff line number Diff line
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
+1 −1
Original line number Diff line number Diff line
@@ -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
Loading