Skip to content

Commit 65cd280

Browse files
committed
moving observe function to toolbar
1 parent e2c17e0 commit 65cd280

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

debug_toolbar/middleware.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ def show_toolbar(request):
2121
return settings.DEBUG and request.META.get("REMOTE_ADDR") in settings.INTERNAL_IPS
2222

2323

24-
def observe_request(request):
25-
"""
26-
Default function to determine whether to update the toolbar from a client side request
27-
"""
28-
return not DebugToolbar.is_toolbar_request(request)
29-
30-
3124
@lru_cache()
3225
def get_show_toolbar():
3326
# If SHOW_TOOLBAR_CALLBACK is a string, which is the recommended
@@ -39,17 +32,6 @@ def get_show_toolbar():
3932
return func_or_path
4033

4134

42-
@lru_cache()
43-
def get_observe_request():
44-
# If OBSERVE_REQUEST_CALLBACK is a string, which is the recommended
45-
# setup, resolve it to the corresponding callable.
46-
func_or_path = dt_settings.get_config()["OBSERVE_REQUEST_CALLBACK"]
47-
if isinstance(func_or_path, str):
48-
return import_string(func_or_path)
49-
else:
50-
return func_or_path
51-
52-
5335
class DebugToolbarMiddleware:
5436
"""
5537
Middleware to set up Debug Toolbar on incoming request and render toolbar

debug_toolbar/panels/history/panel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
from django.utils import timezone
99
from django.utils.translation import gettext_lazy as _
1010

11-
from debug_toolbar.middleware import get_observe_request
1211
from debug_toolbar.panels import Panel
1312
from debug_toolbar.panels.history import views
1413
from debug_toolbar.panels.history.forms import HistoryStoreForm
14+
from debug_toolbar.toolbar import get_observe_request
1515

1616

1717
class HistoryPanel(Panel):

debug_toolbar/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"SHOW_TEMPLATE_CONTEXT": True,
3838
"SKIP_TEMPLATE_PREFIXES": ("django/forms/widgets/", "admin/widgets/"),
3939
"SQL_WARNING_THRESHOLD": 500, # milliseconds
40-
"OBSERVE_REQUEST_CALLBACK": "debug_toolbar.middleware.observe_request",
40+
"OBSERVE_REQUEST_CALLBACK": "debug_toolbar.toolbar.observe_request",
4141
}
4242

4343

debug_toolbar/toolbar.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import uuid
66
from collections import OrderedDict
7+
from functools import lru_cache
78

89
from django.apps import apps
910
from django.core.exceptions import ImproperlyConfigured
@@ -154,3 +155,21 @@ def is_toolbar_request(cls, request):
154155
except Resolver404:
155156
return False
156157
return resolver_match.namespaces and resolver_match.namespaces[-1] == app_name
158+
159+
160+
def observe_request(request):
161+
"""
162+
Default function to determine whether to update the toolbar from a client side request
163+
"""
164+
return not DebugToolbar.is_toolbar_request(request)
165+
166+
167+
@lru_cache()
168+
def get_observe_request():
169+
# If OBSERVE_REQUEST_CALLBACK is a string, which is the recommended
170+
# setup, resolve it to the corresponding callable.
171+
func_or_path = dt_settings.get_config()["OBSERVE_REQUEST_CALLBACK"]
172+
if isinstance(func_or_path, str):
173+
return import_string(func_or_path)
174+
else:
175+
return func_or_path

0 commit comments

Comments
 (0)