aboutsummaryrefslogtreecommitdiffstats
path: root/debug_toolbar
diff options
context:
space:
mode:
authorRob Hudson2008-10-07 12:23:18 -0700
committerRob Hudson2008-10-07 12:35:56 -0700
commit822988142666fccb216a17ef3abbee7b6bbcf76b (patch)
tree5fdc354bcbe19b2e70f8733dc79e902d88f49993 /debug_toolbar
parenta3492e14765e3f898efc26913a8e8c4445a837b4 (diff)
downloaddjango-debug-toolbar-822988142666fccb216a17ef3abbee7b6bbcf76b.tar.bz2
Clicking on a template file now will fetch and show the source of the template.
Thanks to Adam Gomaa for the patch.
Diffstat (limited to 'debug_toolbar')
-rw-r--r--debug_toolbar/media/toolbar.css37
-rw-r--r--debug_toolbar/media/toolbar.min.css2
-rw-r--r--debug_toolbar/templates/debug_toolbar/panels/template_source.html3
-rw-r--r--debug_toolbar/templates/debug_toolbar/panels/templates.html2
-rw-r--r--debug_toolbar/urls.py1
-rw-r--r--debug_toolbar/views.py31
6 files changed, 59 insertions, 17 deletions
diff --git a/debug_toolbar/media/toolbar.css b/debug_toolbar/media/toolbar.css
index f1c303f..2ce4226 100644
--- a/debug_toolbar/media/toolbar.css
+++ b/debug_toolbar/media/toolbar.css
@@ -61,6 +61,10 @@
color: #92ef3f;
}
+#djDebug pre {
+ background-color: #ffffff;
+}
+
#djDebug .panelContent {
background: #2a5738;
@@ -145,17 +149,22 @@
margin-left: 10px;
}
-#djDebug .syntax { color: #000; }
-#djDebug .syntax .err { color: #000; } /* Error */
-#djDebug .syntax .g { color: #000; } /* Generic */
-#djDebug .syntax .k { color: #40684C; font-weight: bold } /* Keyword */
-#djDebug .syntax .o { color: #000; } /* Operator */
-#djDebug .syntax .n { color: #000; } /* Name */
-#djDebug .syntax .mi { color: #40684C; font-weight: bold } /* Literal.Number.Integer */
-#djDebug .syntax .l { color: #000; } /* Literal */
-#djDebug .syntax .x { color: #000; } /* Other */
-#djDebug .syntax .p { color: #000; } /* Punctuation */
-#djDebug .syntax .m { color: #40684C; font-weight: bold } /* Literal.Number */
-#djDebug .syntax .s { color: #0086d2 } /* Literal.String */
-#djDebug .syntax .w { color: #888888 } /* Text.Whitespace */
-#djDebug .syntax .il { color: #40684C; font-weight: bold } /* Literal.Number.Integer.Long */
+#djDebug .highlight { color: #000; }
+#djDebug .highlight .err { color: #000; } /* Error */
+#djDebug .highlight .g { color: #000; } /* Generic */
+#djDebug .highlight .k { color: #40684C; font-weight: bold } /* Keyword */
+#djDebug .highlight .o { color: #000; } /* Operator */
+#djDebug .highlight .n { color: #000; } /* Name */
+#djDebug .highlight .mi { color: #40684C; font-weight: bold } /* Literal.Number.Integer */
+#djDebug .highlight .l { color: #000; } /* Literal */
+#djDebug .highlight .x { color: #000; } /* Other */
+#djDebug .highlight .p { color: #000; } /* Punctuation */
+#djDebug .highlight .m { color: #40684C; font-weight: bold } /* Literal.Number */
+#djDebug .highlight .s { color: #0086d2 } /* Literal.String */
+#djDebug .highlight .w { color: #888888 } /* Text.Whitespace */
+#djDebug .highlight .il { color: #40684C; font-weight: bold } /* Literal.Number.Integer.Long */
+#djDebug .highlight .na { color: #7D9029 } /* Name.Attribute */
+#djDebug .highlight .nt { color: #008000; font-weight: bold } /* Name.Tag */
+#djDebug .highlight .nv { color: #19177C } /* Name.Variable */
+#djDebug .highlight .s2 { color: #BA2121 } /* Literal.String.Double */
+#djDebug .highlight .cp { color: #BC7A00 } /* Comment.Preproc */
diff --git a/debug_toolbar/media/toolbar.min.css b/debug_toolbar/media/toolbar.min.css
index 5be1046..bb7c034 100644
--- a/debug_toolbar/media/toolbar.min.css
+++ b/debug_toolbar/media/toolbar.min.css
@@ -1 +1 @@
-#djDebug *{color:#000;float:none;margin:0;padding:0;position:static;}#djDebug a{color:#f7c757;}#djDebug a:hover{color:#aaa;}#djDebugToolbar{background:#326342;height:30px;z-index:100000000;border-bottom:2px solid #234f32;position:absolute;top:0;left:0;right:0;}#djDebugToolbar ul{margin:0;padding:0;list-style:none;}#djDebugToolbar li{border-left:1px solid #487858;color:#fff;display:inline;font-size:11px;font-weight:bold;float:none;height:20px;margin:0;padding:0;line-height:30px;padding:8px 9px 9px;position:relative;width:auto;}#djDebugToolbar li:hover{background:#487858;}#djDebugToolbar li:hover a{color:#fff;}#djDebugToolbar li:last-child{border-right:1px solid #487858;}#djDebugToolbar #djDebugButton{color:#92ef3f;}#djDebug .panelContent{background:#2a5738;border-bottom:2px solid #234f32;border-top:2px solid #487858;display:none;position:absolute;margin:0;padding:10px;top:32px;width:auto;left:0;right:0;bottom:5px;color:black;z-index:1000000;overflow:auto;}#djDebug .panelContent p a,#djDebug .panelContent dl a{color:#40684c;}#djDebug .panelContent p a:hover,#djDebug .panelContent dl a:hover{color:#92EF3F;}#djDebug .panelContent h3{border-bottom:1px solid #40684c;color:#92ef3f;padding:0 0 5px;}#djDebug .panelContent p{padding:0 5px;}#djDebug .panelContent p,#djDebug .panelContent table,#djDebug .panelContent ol,#djDebug .panelContent ul,#djDebug .panelContent dl{margin:5px 0 15px;background-color:#fff;}#djDebug .panelContent table{width:100%;clear:both;}#djDebug .panelContent table a{color:#40684C;}#djDebug .panelContent table th{background-color:#9dcc49;font-weight:bold;color:#000;font-size:11px;padding:3px 7px 3px;text-align:left;cursor:pointer;border-right:1px solid #b9d977;}#djDebug .panelContent table td{padding:5px 10px;font-size:11px;background:#fff;color:#000;vertical-align:top;}#djDebug .panelContent table tr.odd td{background:#eee;}#djDebug .panelContent .close{float:right;font-weight:bold;}#djDebug .panelContent dt,#djDebug .panelContent dd{display:block;}#djDebug .panelContent dd{margin-left:10px;}#djDebug .syntax{color:#000;}#djDebug .syntax .err{color:#000;}#djDebug .syntax .g{color:#000;}#djDebug .syntax .k{color:#40684C;font-weight:bold;}#djDebug .syntax .o{color:#000;}#djDebug .syntax .n{color:#000;}#djDebug .syntax .mi{color:#40684C;font-weight:bold;}#djDebug .syntax .l{color:#000;}#djDebug .syntax .x{color:#000;}#djDebug .syntax .p{color:#000;}#djDebug .syntax .m{color:#40684C;font-weight:bold;}#djDebug .syntax .s{color:#0086d2;}#djDebug .syntax .w{color:#888;}#djDebug .syntax .il{color:#40684C;font-weight:bold;} \ No newline at end of file
+#djDebug *{color:#000;float:none;margin:0;padding:0;position:static;}#djDebug a{color:#f7c757;}#djDebug a:hover{color:#aaa;}#djDebugToolbar{background:#326342;height:30px;z-index:100000000;border-bottom:2px solid #234f32;position:absolute;top:0;left:0;right:0;}#djDebugToolbar ul{margin:0;padding:0;list-style:none;}#djDebugToolbar li{border-left:1px solid #487858;color:#fff;display:inline;font-size:11px;font-weight:bold;float:none;height:20px;margin:0;padding:0;line-height:30px;padding:8px 9px 9px;position:relative;width:auto;}#djDebugToolbar li:hover{background:#487858;}#djDebugToolbar li:hover a{color:#fff;}#djDebugToolbar li:last-child{border-right:1px solid #487858;}#djDebugToolbar #djDebugButton{color:#92ef3f;}#djDebug pre{background-color:#fff;}#djDebug .panelContent{background:#2a5738;border-bottom:2px solid #234f32;border-top:2px solid #487858;display:none;position:absolute;margin:0;padding:10px;top:32px;width:auto;left:0;right:0;bottom:5px;color:black;z-index:1000000;overflow:auto;}#djDebug .panelContent p a,#djDebug .panelContent dl a{color:#40684c;}#djDebug .panelContent p a:hover,#djDebug .panelContent dl a:hover{color:#92EF3F;}#djDebug .panelContent h3{border-bottom:1px solid #40684c;color:#92ef3f;padding:0 0 5px;}#djDebug .panelContent p{padding:0 5px;}#djDebug .panelContent p,#djDebug .panelContent table,#djDebug .panelContent ol,#djDebug .panelContent ul,#djDebug .panelContent dl{margin:5px 0 15px;background-color:#fff;}#djDebug .panelContent table{width:100%;clear:both;}#djDebug .panelContent table a{color:#40684C;}#djDebug .panelContent table th{background-color:#9dcc49;font-weight:bold;color:#000;font-size:11px;padding:3px 7px 3px;text-align:left;cursor:pointer;border-right:1px solid #b9d977;}#djDebug .panelContent table td{padding:5px 10px;font-size:11px;background:#fff;color:#000;vertical-align:top;}#djDebug .panelContent table tr.odd td{background:#eee;}#djDebug .panelContent .close{float:right;font-weight:bold;}#djDebug .panelContent dt,#djDebug .panelContent dd{display:block;}#djDebug .panelContent dd{margin-left:10px;}#djDebug .highlight{color:#000;}#djDebug .highlight .err{color:#000;}#djDebug .highlight .g{color:#000;}#djDebug .highlight .k{color:#40684C;font-weight:bold;}#djDebug .highlight .o{color:#000;}#djDebug .highlight .n{color:#000;}#djDebug .highlight .mi{color:#40684C;font-weight:bold;}#djDebug .highlight .l{color:#000;}#djDebug .highlight .x{color:#000;}#djDebug .highlight .p{color:#000;}#djDebug .highlight .m{color:#40684C;font-weight:bold;}#djDebug .highlight .s{color:#0086d2;}#djDebug .highlight .w{color:#888;}#djDebug .highlight .il{color:#40684C;font-weight:bold;}#djDebug .highlight .na{color:#7D9029;}#djDebug .highlight .nt{color:#008000;font-weight:bold;}#djDebug .highlight .nv{color:#19177C;}#djDebug .highlight .s2{color:#BA2121;}#djDebug .highlight .cp{color:#BC7A00;} \ No newline at end of file
diff --git a/debug_toolbar/templates/debug_toolbar/panels/template_source.html b/debug_toolbar/templates/debug_toolbar/panels/template_source.html
new file mode 100644
index 0000000..572522b
--- /dev/null
+++ b/debug_toolbar/templates/debug_toolbar/panels/template_source.html
@@ -0,0 +1,3 @@
+<a class="back" href="">&laquo;&nbsp;Back</a>
+<h3>Template Source: <samp>{{ template_name }}</samp></h3>
+{{ source }}
diff --git a/debug_toolbar/templates/debug_toolbar/panels/templates.html b/debug_toolbar/templates/debug_toolbar/panels/templates.html
index a92657b..6c918b1 100644
--- a/debug_toolbar/templates/debug_toolbar/panels/templates.html
+++ b/debug_toolbar/templates/debug_toolbar/panels/templates.html
@@ -12,7 +12,7 @@
{% if templates %}
<dl>
{% for template in templates %}
- <dt><strong>{{ template.template.name|addslashes }}</strong></dt>
+ <dt><strong><a class="remoteCall" href="/__debug__/template_source/?template={{ template.template.name }}">{{ template.template.name|addslashes }}</a></strong></dt>
<dd><samp>{{ template.template.origin_name|addslashes }}</samp></dd>
<dd>
<div class="djTemplateShowContextDiv"><a class="djTemplateShowContext">Toggle Context</a></div>
diff --git a/debug_toolbar/urls.py b/debug_toolbar/urls.py
index 53a426b..77d1a80 100644
--- a/debug_toolbar/urls.py
+++ b/debug_toolbar/urls.py
@@ -12,4 +12,5 @@ urlpatterns = patterns('',
url(r'^__debug__/sql_select/$', 'debug_toolbar.views.sql_select', name='sql_select'),
url(r'^__debug__/sql_explain/$', 'debug_toolbar.views.sql_explain', name='sql_explain'),
url(r'^__debug__/sql_profile/$', 'debug_toolbar.views.sql_profile', name='sql_profile'),
+ url(r'^__debug__/template_source/$', 'debug_toolbar.views.template_source', name='template_source'),
)
diff --git a/debug_toolbar/views.py b/debug_toolbar/views.py
index 8af879f..b75397b 100644
--- a/debug_toolbar/views.py
+++ b/debug_toolbar/views.py
@@ -8,7 +8,7 @@ import os
import django.views.static
from django.conf import settings
from django.db import connection
-from django.http import HttpResponse
+from django.http import HttpResponse, HttpResponseBadRequest
from django.shortcuts import render_to_response
from django.utils import simplejson
from django.utils.hashcompat import sha_constructor
@@ -116,3 +116,32 @@ def sql_profile(request):
'headers': headers,
}
return render_to_response('debug_toolbar/panels/sql_explain.html', context)
+
+def template_source(request):
+ """
+ Return the source of a template, syntax-highlighted by Pygments if
+ it's available.
+ """
+ from django.template.loader import find_template_source
+ from django.utils.safestring import mark_safe
+
+ template_name = request.GET.get('template', None)
+ if template_name is None:
+ return HttpResponseBadRequest('"template" key is required')
+
+ source, origin = find_template_source(template_name)
+
+ try:
+ from pygments import highlight
+ from pygments.lexers import HtmlDjangoLexer
+ from pygments.formatters import HtmlFormatter
+
+ source = highlight(source, HtmlDjangoLexer(), HtmlFormatter())
+ source = mark_safe(source)
+ except ImportError:
+ pass
+
+ return render_to_response('debug_toolbar/panels/template_source.html', {
+ 'source': source,
+ 'template_name': template_name
+ })