Skip to content

Commit cb428ce

Browse files
committed
Restore support for callables in SHOW_TOOLBAR_CALLBACK.
Fix #523.
1 parent d2cb9b1 commit cb428ce

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

debug_toolbar/middleware.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
from django.conf import settings
1515
from django.utils.encoding import force_text
16+
from django.utils import six
1617

1718
from debug_toolbar.toolbar import DebugToolbar
1819
from debug_toolbar import settings as dt_settings
@@ -42,13 +43,20 @@ class DebugToolbarMiddleware(object):
4243
"""
4344
debug_toolbars = {}
4445

46+
def __init__(self):
47+
# If SHOW_TOOLBAR_CALLBACK is a string, which is the recommended
48+
# setup, resolve it to the corresponding callable.
49+
func_or_path = dt_settings.CONFIG['SHOW_TOOLBAR_CALLBACK']
50+
if isinstance(func_or_path, six.string_types):
51+
# Replace this with import_by_path in Django >= 1.6.
52+
mod_path, func_name = func_or_path.rsplit('.', 1)
53+
self.show_toolbar = getattr(import_module(mod_path), func_name)
54+
else:
55+
self.show_toolbar = func_or_path
56+
4557
def process_request(self, request):
4658
# Decide whether the toolbar is active for this request.
47-
func_path = dt_settings.CONFIG['SHOW_TOOLBAR_CALLBACK']
48-
# Replace this with import_by_path in Django >= 1.6.
49-
mod_path, func_name = func_path.rsplit('.', 1)
50-
show_toolbar = getattr(import_module(mod_path), func_name)
51-
if not show_toolbar(request):
59+
if not self.show_toolbar(request):
5260
return
5361

5462
toolbar = DebugToolbar(request)

debug_toolbar/settings.py

-4
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@
6868

6969
CONFIG = CONFIG_DEFAULTS.copy()
7070
CONFIG.update(USER_CONFIG)
71-
if not isinstance(CONFIG['SHOW_TOOLBAR_CALLBACK'], six.string_types):
72-
warnings.warn(
73-
"SHOW_TOOLBAR_CALLBACK is now a dotted path. Update your "
74-
"DEBUG_TOOLBAR_CONFIG setting.", DeprecationWarning)
7571

7672

7773
PANELS_DEFAULTS = [

0 commit comments

Comments
 (0)