From b345cb5f20bb4dea6c918ef05b844670439f4b73 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Wed, 29 Jun 2016 17:08:46 -0700 Subject: [PATCH 1/2] Add SessionAuthenticationMiddleware to test settings.py to silence warning --- tests/settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/settings.py b/tests/settings.py index dddb88a71..834707b5d 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -32,6 +32,7 @@ MIDDLEWARE_CLASSES = [ 'debug_toolbar.middleware.DebugToolbarMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', From 388e177eb19a2b51f7663003a1aa509ee56bbb7a Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Wed, 27 Jul 2016 16:44:46 +0200 Subject: [PATCH 2/2] Make DebugToolarMiddleware compatible with Django 1.10's MIDDLEWARE setting Fixes #853. --- debug_toolbar/middleware.py | 17 +++++++++++++---- docs/changes.rst | 17 +++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/debug_toolbar/middleware.py b/debug_toolbar/middleware.py index 1fb3e270a..4b91bae6a 100644 --- a/debug_toolbar/middleware.py +++ b/debug_toolbar/middleware.py @@ -10,11 +10,19 @@ from django.conf import settings from django.utils import six from django.utils.encoding import force_text +from django.utils.functional import cached_property from django.utils.module_loading import import_string from debug_toolbar import settings as dt_settings from debug_toolbar.toolbar import DebugToolbar +try: + from django.utils.deprecation import MiddlewareMixin +except ImportError: # Django < 1.10 + # Works perfectly for everyone using MIDDLEWARE_CLASSES + MiddlewareMixin = object + + _HTML_TYPES = ('text/html', 'application/xhtml+xml') @@ -31,21 +39,22 @@ def show_toolbar(request): return bool(settings.DEBUG) -class DebugToolbarMiddleware(object): +class DebugToolbarMiddleware(MiddlewareMixin): """ Middleware to set up Debug Toolbar on incoming request and render toolbar on outgoing response. """ debug_toolbars = {} - def __init__(self): + @cached_property + def show_toolbar(self): # If SHOW_TOOLBAR_CALLBACK is a string, which is the recommended # setup, resolve it to the corresponding callable. func_or_path = dt_settings.get_config()['SHOW_TOOLBAR_CALLBACK'] if isinstance(func_or_path, six.string_types): - self.show_toolbar = import_string(func_or_path) + return import_string(func_or_path) else: - self.show_toolbar = func_or_path + return func_or_path def process_request(self, request): # Decide whether the toolbar is active for this request. diff --git a/docs/changes.rst b/docs/changes.rst index a176e2b41..b6454bbce 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -1,6 +1,23 @@ Change log ========== +1.6 (upcoming) +-------------- + +Removed features +~~~~~~~~~~~~~~~~ + +* Support for automatic setup has been removed. Installation now requires + explicit setup. As a result, the ``DEBUG_TOOLBAR_PATCH_SETTINGS`` setting has + also been removed. See the :doc:`installation documentation ` + for details. + +Bugfixes +~~~~~~~~ + +* The ``DebugToolbarMiddleware`` now also supports Django 1.10's ``MIDDLEWARE`` + setting. + 1.5 ---