Ticket #19321: 19321.patch

File 19321.patch, 1.5 KB (added by Aymeric Augustin, 12 years ago)
  • django/contrib/redirects/middleware.py

    diff --git a/django/contrib/redirects/middleware.py b/django/contrib/redirects/middleware.py
    index 03c9d97..9053c64 100644
    a b from django import http  
    88
    99
    1010class RedirectFallbackMiddleware(object):
     11
     12    # Defined as class-level attributes to be subclassing-friendly.
     13    response_gone_class = http.HttpResponseGone
     14    response_redirect_class = http.HttpResponsePermanentRedirect
     15
    1116    def __init__(self):
    1217        if 'django.contrib.sites' not in settings.INSTALLED_APPS:
    1318            raise ImproperlyConfigured(
    class RedirectFallbackMiddleware(object):  
    1621            )
    1722
    1823    def process_response(self, request, response):
     24        # No need to check for a redirect for non-404 responses.
    1925        if response.status_code != 404:
    20             return response # No need to check for a redirect for non-404 responses.
     26            return response
    2127
    2228        full_path = request.get_full_path()
    2329        current_site = get_current_site(request)
    class RedirectFallbackMiddleware(object):  
    3743                pass
    3844        if r is not None:
    3945            if r.new_path == '':
    40                 return http.HttpResponseGone()
    41             return http.HttpResponsePermanentRedirect(r.new_path)
     46                return self.response_gone_class()
     47            return self.response_redirect_class(r.new_path)
    4248
    4349        # No redirect was found. Return the response.
    4450        return response
Back to Top