Skip to content

Wrap panel process_view requests to allow multiple panels to hook without calling the view multiple times #204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions debug_toolbar/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
import imp
import thread
from functools import wraps

from django.conf import settings
from django.conf.urls.defaults import include, patterns
Expand Down Expand Up @@ -97,14 +98,25 @@ def process_request(self, request):
for panel in toolbar.panels:
panel.process_request(request)
self.__class__.debug_toolbars[thread.get_ident()] = toolbar


def _wrap_view(self, view_func, panel):
@wraps(view_func)
def _wrapped_view(request, *view_args, **view_kwargs):
ret = panel.process_view(request, view_func, view_args, view_kwargs)
if ret is None: # call the next panel if this one didn't do it
ret = view_func( request, *view_args, **view_kwargs )
return ret
return _wrapped_view

def process_view(self, request, view_func, view_args, view_kwargs):
__traceback_hide__ = True
toolbar = self.__class__.debug_toolbars.get(thread.get_ident())
if not toolbar:
return
wrapped_view_func = view_func
for panel in toolbar.panels:
panel.process_view(request, view_func, view_args, view_kwargs)
wrapped_view_func = self._wrap_view( wrapped_view_func, panel )
return wrapped_view_func(request, *view_args, **view_kwargs)

def process_response(self, request, response):
__traceback_hide__ = True
Expand Down