diff options
| author | David Cramer | 2011-06-14 12:54:46 -0700 |
|---|---|---|
| committer | David Cramer | 2011-06-14 12:54:46 -0700 |
| commit | b431d64f3b9722f7ae17f30f0168412d419c0d43 (patch) | |
| tree | 71e6f303fc777a24020024bf5b223e6f78dbc4c6 /debug_toolbar/utils/__init__.py | |
| parent | 7504141f19ef1bdaaf91d95461dad35ac84b5211 (diff) | |
| download | django-debug-toolbar-b431d64f3b9722f7ae17f30f0168412d419c0d43.tar.bz2 | |
Moved view function name extraction into debug_toolbar.utils.get_name_from_obj
Diffstat (limited to 'debug_toolbar/utils/__init__.py')
| -rw-r--r-- | debug_toolbar/utils/__init__.py | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/debug_toolbar/utils/__init__.py b/debug_toolbar/utils/__init__.py index 2ce38db..c4dc160 100644 --- a/debug_toolbar/utils/__init__.py +++ b/debug_toolbar/utils/__init__.py @@ -47,7 +47,7 @@ def get_template_info(source, context_lines=3): line = 0 upto = 0 source_lines = [] - before = during = after = "" + # before = during = after = "" origin, (start, end) = source template_source = origin.reload() @@ -55,9 +55,9 @@ def get_template_info(source, context_lines=3): for num, next in enumerate(linebreak_iter(template_source)): if start >= upto and end <= next: line = num - before = template_source[upto:start] - during = template_source[start:end] - after = template_source[end:next] + # before = template_source[upto:start] + # during = template_source[start:end] + # after = template_source[end:next] source_lines.append((num, template_source[upto:next])) upto = next @@ -75,4 +75,18 @@ def get_template_info(source, context_lines=3): return { 'name': origin.name, 'context': context, - }
\ No newline at end of file + } + +def get_name_from_obj(obj): + if hasattr(obj, '__name__'): + name = obj.__name__ + elif hasattr(obj, '__class__') and hasattr(obj.__class__, '__name__'): + name = obj.__class__.__name__ + else: + name = '<unknown>' + + if hasattr(obj, '__module__'): + module = obj.__module__ + name = '%s.%s' % (module, name) + + return name
\ No newline at end of file |
