Skip to content

Commit 0de0d0f

Browse files
committed
Move get_observe_request to DebugToolbar
This avoids having to import the function within a panel.
1 parent 938d731 commit 0de0d0f

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

debug_toolbar/panels/history/panel.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from debug_toolbar.panels import Panel
1212
from debug_toolbar.panels.history import views
1313
from debug_toolbar.panels.history.forms import HistoryStoreForm
14-
from debug_toolbar.toolbar import get_observe_request
1514

1615

1716
class HistoryPanel(Panel):
@@ -23,7 +22,7 @@ class HistoryPanel(Panel):
2322

2423
def get_headers(self, request):
2524
headers = super().get_headers(request)
26-
observe_request = get_observe_request()
25+
observe_request = self.toolbar.get_observe_request()
2726
store_id = getattr(self.toolbar, "store_id")
2827
if store_id and observe_request(request):
2928
headers["DJDT-STORE-ID"] = store_id

debug_toolbar/toolbar.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,20 +156,20 @@ def is_toolbar_request(cls, request):
156156
return False
157157
return resolver_match.namespaces and resolver_match.namespaces[-1] == app_name
158158

159+
@staticmethod
160+
@lru_cache
161+
def get_observe_request():
162+
# If OBSERVE_REQUEST_CALLBACK is a string, which is the recommended
163+
# setup, resolve it to the corresponding callable.
164+
func_or_path = dt_settings.get_config()["OBSERVE_REQUEST_CALLBACK"]
165+
if isinstance(func_or_path, str):
166+
return import_string(func_or_path)
167+
else:
168+
return func_or_path
169+
159170

160171
def observe_request(request):
161172
"""
162-
Default function to determine whether to update the toolbar from a client side request
173+
Determine whether to update the toolbar from a client side request.
163174
"""
164175
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)