Ticket #19779: 19779-1.diff

File 19779-1.diff, 4.1 KB (added by Claude Paroz, 11 years ago)
  • django/contrib/redirects/middleware.py

    diff --git a/django/contrib/redirects/middleware.py b/django/contrib/redirects/middleware.py
    index f5d3594..1aaef17 100644
    a b  
    11from __future__ import unicode_literals
    22
     3from django.conf import settings
    34from django.contrib.redirects.models import Redirect
    45from django.contrib.sites.models import get_current_site
     6from django.core.exceptions import ImproperlyConfigured
    57from django import http
    6 from django.conf import settings
    78
    89class RedirectFallbackMiddleware(object):
     10    def __init__(self):
     11        if 'django.contrib.sites' not in settings.INSTALLED_APPS:
     12            raise ImproperlyConfigured(
     13                "You cannot use RedirectFallbackMiddleware when "
     14                "django.contrib.sites is not installed."
     15            )
     16
    917    def process_response(self, request, response):
    1018        if response.status_code != 404:
    1119            return response # No need to check for a redirect for non-404 responses.
  • django/contrib/redirects/tests.py

    diff --git a/django/contrib/redirects/tests.py b/django/contrib/redirects/tests.py
    index 4ea8523..7170520 100644
    a b  
    11from django.conf import settings
    22from django.contrib.sites.models import Site
     3from django.core.exceptions import ImproperlyConfigured
    34from django.test import TestCase
    45from django.test.utils import override_settings
    56from django.utils import six
    67
     8from .middleware import RedirectFallbackMiddleware
    79from .models import Redirect
    810
    911
    class RedirectTests(TestCase):  
    5254            site=self.site, old_path='/initial', new_path='')
    5355        response = self.client.get('/initial')
    5456        self.assertEqual(response.status_code, 410)
     57
     58    @override_settings(
     59        INSTALLED_APPS=[app for app in settings.INSTALLED_APPS
     60                        if app != 'django.contrib.sites'])
     61    def test_sites_not_installed(self):
     62        with self.assertRaises(ImproperlyConfigured):
     63            _ = RedirectFallbackMiddleware()
  • docs/ref/contrib/redirects.txt

    diff --git a/docs/ref/contrib/redirects.txt b/docs/ref/contrib/redirects.txt
    index e34ba40..0c0cb2a 100644
    a b Installation  
    1313
    1414To install the redirects app, follow these steps:
    1515
    16 1. Add ``'django.contrib.redirects'`` to your :setting:`INSTALLED_APPS`
    17    setting.
    18 2. Add ``'django.contrib.redirects.middleware.RedirectFallbackMiddleware'``
     161. Ensure that the ``django.contrib.sites`` framework
     17   :ref:`is installed <enabling-the-sites-framework>`.
     182. Add ``'django.contrib.redirects'`` to your :setting:`INSTALLED_APPS` setting.
     193. Add ``'django.contrib.redirects.middleware.RedirectFallbackMiddleware'``
    1920   to your :setting:`MIDDLEWARE_CLASSES` setting.
    20 3. Run the command :djadmin:`manage.py syncdb <syncdb>`.
     214. Run the command :djadmin:`manage.py syncdb <syncdb>`.
    2122
    2223How it works
    2324============
  • docs/ref/contrib/sites.txt

    diff --git a/docs/ref/contrib/sites.txt b/docs/ref/contrib/sites.txt
    index 7eaab5d..139a9b3 100644
    a b To do this, you can use the sites framework. A simple example::  
    246246    >>> 'http://%s%s' % (Site.objects.get_current().domain, obj.get_absolute_url())
    247247    'http://example.com/mymodel/objects/3/'
    248248
     249.. _enabling-the-sites-framework:
    249250
    250251Enabling the sites framework
    251252============================
  • docs/releases/1.5.txt

    diff --git a/docs/releases/1.5.txt b/docs/releases/1.5.txt
    index a5ce08a..33dcb0e 100644
    a b Miscellaneous  
    653653  Attempting to load it with ``{% load adminmedia %}`` will fail. If your
    654654  templates still contain that line you must remove it.
    655655
     656* Because of an implementation oversight, it was possible to use
     657  :doc:`django.contrib.redirects </ref/contrib/redirects>` without enabling
     658  :doc:`django.contrib.sites </ref/contrib/sites>`. This isn't allowed any
     659  longer. If you're using ``django.contrib.redirects``, make sure
     660  :setting:``INSTALLED_APPS`` contains ``django.contrib.sites``.
     661
    656662Features deprecated in 1.5
    657663==========================
    658664
Back to Top