From a77ee9cee43ec01f43bebc71ad64702fa110b475 Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Mon, 15 Sep 2008 17:43:10 +0100 Subject: Added a mechanism for monkeypatching in debug views, and also added jquery as both a test case and a place to get started making some js improvements. I'm not totally thrilled with this approach -- it feels *very* hackish. The alternative might be to simply require installers to add a line to their ROOT_URLCONF, which wouldn't be *bad*, but I like the "load automatically" part of this thing. --- debug_toolbar/middleware.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'debug_toolbar/middleware.py') diff --git a/debug_toolbar/middleware.py b/debug_toolbar/middleware.py index ee00448..a7e5655 100644 --- a/debug_toolbar/middleware.py +++ b/debug_toolbar/middleware.py @@ -4,6 +4,8 @@ Debug Toolbar middleware import re from django.conf import settings from django.utils.encoding import smart_str +from django.conf.urls.defaults import include, patterns +import debug_toolbar.urls from debug_toolbar.toolbar.loader import DebugToolbar _HTML_TYPES = ('text/html', 'application/xhtml+xml') @@ -31,6 +33,18 @@ class DebugToolbarMiddleware(object): if self.show_toolbar(request): self.debug_toolbar = DebugToolbar(request) self.debug_toolbar.load_panels() + + # Monkeypatch in the URLpatterns for the debug toolbar. The last item + # in the URLpatterns needs to be ```('', include(ROOT_URLCONF))``` so + # that the existing URLs load *after* the ones we patch in. However, + # this is difficult to get right: a previous middleware might have + # changed request.urlconf, so we need to pick that up instead. + original_urlconf = getattr(request, 'urlconf', settings.ROOT_URLCONF) + debug_toolbar.urls.urlpatterns += patterns('', + ('', include(original_urlconf)), + ) + request.urlconf = 'debug_toolbar.urls' + return None def process_response(self, request, response): -- cgit v1.2.3