Skip to content

Commit

Permalink
Restore support for callables in SHOW_TOOLBAR_CALLBACK.
Browse files Browse the repository at this point in the history
Fix #523.
  • Loading branch information
aaugustin committed Nov 1, 2014
1 parent d2cb9b1 commit cb428ce
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
18 changes: 13 additions & 5 deletions debug_toolbar/middleware.py
Expand Up @@ -13,6 +13,7 @@

from django.conf import settings
from django.utils.encoding import force_text
from django.utils import six

from debug_toolbar.toolbar import DebugToolbar
from debug_toolbar import settings as dt_settings
Expand Down Expand Up @@ -42,13 +43,20 @@ class DebugToolbarMiddleware(object):
"""
debug_toolbars = {}

def __init__(self):
# If SHOW_TOOLBAR_CALLBACK is a string, which is the recommended
# setup, resolve it to the corresponding callable.
func_or_path = dt_settings.CONFIG['SHOW_TOOLBAR_CALLBACK']
if isinstance(func_or_path, six.string_types):
# Replace this with import_by_path in Django >= 1.6.
mod_path, func_name = func_or_path.rsplit('.', 1)
self.show_toolbar = getattr(import_module(mod_path), func_name)
else:
self.show_toolbar = func_or_path

def process_request(self, request):
# Decide whether the toolbar is active for this request.
func_path = dt_settings.CONFIG['SHOW_TOOLBAR_CALLBACK']
# Replace this with import_by_path in Django >= 1.6.
mod_path, func_name = func_path.rsplit('.', 1)
show_toolbar = getattr(import_module(mod_path), func_name)
if not show_toolbar(request):
if not self.show_toolbar(request):
return

toolbar = DebugToolbar(request)
Expand Down
4 changes: 0 additions & 4 deletions debug_toolbar/settings.py
Expand Up @@ -68,10 +68,6 @@

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


PANELS_DEFAULTS = [
Expand Down

0 comments on commit cb428ce

Please sign in to comment.