File tree Expand file tree Collapse file tree 4 files changed +21
-20
lines changed Expand file tree Collapse file tree 4 files changed +21
-20
lines changed Original file line number Diff line number Diff 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 ()
3225def 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-
5335class DebugToolbarMiddleware :
5436 """
5537 Middleware to set up Debug Toolbar on incoming request and render toolbar
Original file line number Diff line number Diff line change 88from django .utils import timezone
99from django .utils .translation import gettext_lazy as _
1010
11- from debug_toolbar .middleware import get_observe_request
1211from debug_toolbar .panels import Panel
1312from debug_toolbar .panels .history import views
1413from debug_toolbar .panels .history .forms import HistoryStoreForm
14+ from debug_toolbar .toolbar import get_observe_request
1515
1616
1717class HistoryPanel (Panel ):
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 44
55import uuid
66from collections import OrderedDict
7+ from functools import lru_cache
78
89from django .apps import apps
910from 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
You can’t perform that action at this time.
0 commit comments