Skip to content

Commit

Permalink
Make DebugToolarMiddleware compatible with Django 1.10's MIDDLEWARE s…
Browse files Browse the repository at this point in the history
…etting

Fixes #853.
  • Loading branch information
matthiask committed Aug 20, 2016
1 parent 96b5c48 commit 388e177
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
17 changes: 13 additions & 4 deletions debug_toolbar/middleware.py
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
@@ -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

0 comments on commit 388e177

Please sign in to comment.