Skip to content

Commit

Permalink
v0.4.0 a different method of unwrapping class based views
Browse files Browse the repository at this point in the history
  • Loading branch information
dmclain committed Feb 19, 2014
1 parent 88dea29 commit 1d9f770
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions debug_toolbar_line_profiler/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.utils.safestring import mark_safe
from django.utils.six.moves import cStringIO
from debug_toolbar.panels import Panel
from django.views.generic.base import View

from line_profiler import LineProfiler, show_func

Expand Down Expand Up @@ -165,10 +166,12 @@ def process_view(self, request, view_func, view_args, view_kwargs):
self.line_profiler = LineProfiler()
self._unwrap_closure_and_profile(view_func)
if view_func.func_globals['__name__'] == 'django.views.generic.base':
class_based_view = view_func.func_closure[1].cell_contents
for name, value in inspect.getmembers(class_based_view):
if name[0] != '_' and inspect.ismethod(value):
self._unwrap_closure_and_profile(value)
for cell in view_func.func_closure:
target = cell.cell_contents
if inspect.isclass(target) and View in inspect.getmro(target):
for name, value in inspect.getmembers(target):
if name[0] != '_' and inspect.ismethod(value):
self._unwrap_closure_and_profile(value)
self.line_profiler.enable_by_count()
out = self.profiler.runcall(view_func, *args, **view_kwargs)
self.line_profiler.disable_by_count()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='django-debug-toolbar-line-profiler',
version='0.3.0',
version='0.4.0',
description='A panel for django-debug-toolbar that integrates ' +
'information from line_profiler',
long_description=open('README.rst').read(),
Expand Down

0 comments on commit 1d9f770

Please sign in to comment.