|
1 | 1 | """
|
2 | 2 | Debug Toolbar middleware
|
3 | 3 | """
|
| 4 | +import imp |
4 | 5 | import thread
|
5 | 6 |
|
6 | 7 | from django.conf import settings
|
| 8 | +from django.conf.urls.defaults import include, patterns |
7 | 9 | from django.http import HttpResponseRedirect
|
8 | 10 | from django.shortcuts import render_to_response
|
9 | 11 | from django.utils.encoding import smart_unicode
|
10 |
| -from django.conf.urls.defaults import include, patterns |
11 | 12 |
|
12 | 13 | import debug_toolbar.urls
|
13 | 14 | from debug_toolbar.toolbar.loader import DebugToolbar
|
@@ -71,26 +72,25 @@ def process_request(self, request):
|
71 | 72 | __traceback_hide__ = True
|
72 | 73 | if self.show_toolbar(request):
|
73 | 74 |
|
74 |
| - urlconf_name = getattr(request, 'urlconf', settings.ROOT_URLCONF) |
75 |
| - if urlconf_name not in self._urlconfs: |
76 |
| - |
77 |
| - import imp |
| 75 | + urlconf = getattr(request, 'urlconf', settings.ROOT_URLCONF) |
| 76 | + if isinstance(urlconf, basestring): |
| 77 | + urlconf = __import__(getattr(request, 'urlconf', settings.ROOT_URLCONF), {}, {}, ['*']) |
78 | 78 |
|
79 |
| - original_urlconf = __import__(getattr(request, 'urlconf', settings.ROOT_URLCONF), {}, {}, ['*']) |
| 79 | + if urlconf not in self._urlconfs: |
80 | 80 | new_urlconf = imp.new_module('urlconf')
|
81 | 81 | new_urlconf.urlpatterns = debug_toolbar.urls.urlpatterns + \
|
82 | 82 | patterns('',
|
83 |
| - ('', include(original_urlconf)), |
84 |
| - ) |
| 83 | + ('', include(urlconf)), |
| 84 | + ) |
85 | 85 |
|
86 |
| - if hasattr(original_urlconf, 'handler404'): |
87 |
| - new_urlconf.handler404 = original_urlconf.handler404 |
88 |
| - if hasattr(original_urlconf, 'handler500'): |
89 |
| - new_urlconf.handler500 = original_urlconf.handler500 |
90 |
| - |
91 |
| - self._urlconfs[urlconf_name] = new_urlconf |
92 |
| - |
93 |
| - request.urlconf = self._urlconfs[urlconf_name] |
| 86 | + if hasattr(urlconf, 'handler404'): |
| 87 | + new_urlconf.handler404 = urlconf.handler404 |
| 88 | + if hasattr(urlconf, 'handler500'): |
| 89 | + new_urlconf.handler500 = urlconf.handler500 |
| 90 | + |
| 91 | + self._urlconfs[urlconf] = new_urlconf |
| 92 | + |
| 93 | + request.urlconf = self._urlconfs[urlconf] |
94 | 94 |
|
95 | 95 | toolbar = DebugToolbar(request)
|
96 | 96 | for panel in toolbar.panels:
|
|
0 commit comments