Skip to content

Make DebugToolarMiddleware compatible with Django 1.10's MIDDLEWARE setting #864

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions debug_toolbar/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')


Expand All @@ -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.
Expand Down
17 changes: 17 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
@@ -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 <installation>`
for details.

Bugfixes
~~~~~~~~

* The ``DebugToolbarMiddleware`` now also supports Django 1.10's ``MIDDLEWARE``
setting.

1.5
---

Expand Down
1 change: 1 addition & 0 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down