aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Cramer2011-05-26 02:33:35 -0700
committerDavid Cramer2011-05-26 02:33:35 -0700
commiteb5fecd3fe9db5d69d1fa24723235c2d4b356b28 (patch)
tree9618aa8beca040224bb09deb860466b3da03b048
parent77b13141ee6fe86b40bb10f522e25e7c97eac52c (diff)
parent4e072062d1e3725e05518ae23231c375deee59cd (diff)
downloaddjango-debug-toolbar-eb5fecd3fe9db5d69d1fa24723235c2d4b356b28.tar.bz2
Merge pull request #165 from eventbrite/request-urlconf
Accommodate per request URL confs
-rw-r--r--debug_toolbar/middleware.py30
1 files changed, 20 insertions, 10 deletions
diff --git a/debug_toolbar/middleware.py b/debug_toolbar/middleware.py
index 8d77297..7cdf7b0 100644
--- a/debug_toolbar/middleware.py
+++ b/debug_toolbar/middleware.py
@@ -38,8 +38,8 @@ class DebugToolbarMiddleware(object):
return cls.debug_toolbars.get(thread.get_ident())
def __init__(self):
- self.override_url = True
-
+ self._urlconfs = {}
+
# Set method to use to decide to show toolbar
self.show_toolbar = self._show_toolbar # default
@@ -70,17 +70,27 @@ class DebugToolbarMiddleware(object):
def process_request(self, request):
__traceback_hide__ = True
if self.show_toolbar(request):
- if self.override_url:
+
+ urlconf_name = getattr(request, 'urlconf', settings.ROOT_URLCONF)
+ if urlconf_name not in self._urlconfs:
+
+ import imp
+
original_urlconf = __import__(getattr(request, 'urlconf', settings.ROOT_URLCONF), {}, {}, ['*'])
- debug_toolbar.urls.urlpatterns += patterns('',
- ('', include(original_urlconf)),
- )
+ new_urlconf = imp.new_module('urlconf')
+ new_urlconf.urlpatterns = debug_toolbar.urls.urlpatterns + \
+ patterns('',
+ ('', include(original_urlconf)),
+ )
+
if hasattr(original_urlconf, 'handler404'):
- debug_toolbar.urls.handler404 = original_urlconf.handler404
+ new_urlconf.handler404 = original_urlconf.handler404
if hasattr(original_urlconf, 'handler500'):
- debug_toolbar.urls.handler500 = original_urlconf.handler500
- self.override_url = False
- request.urlconf = 'debug_toolbar.urls'
+ new_urlconf.handler500 = original_urlconf.handler500
+
+ self._urlconfs[urlconf_name] = new_urlconf
+
+ request.urlconf = self._urlconfs[urlconf_name]
toolbar = DebugToolbar(request)
for panel in toolbar.panels: