Add simple template panel

This commit is contained in:
mvantellingen
2011-02-02 23:42:43 +01:00
parent 79dc15a4db
commit b3a9627167
3 changed files with 67 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
from flask import template_rendered
from flaskext.debugtoolbar.panels import DebugPanel
_ = lambda x: x
class TemplateDebugPanel(DebugPanel):
"""
Panel that displays the time a response took in milliseconds.
"""
name = 'Timer'
has_content = True
def __init__(self, *args, **kwargs):
super(self.__class__, self).__init__(*args, **kwargs)
self.templates = []
template_rendered.connect(self._store_template_info)
def _store_template_info(self, sender, **kwargs):
self.templates.append(kwargs)
def process_request(self, request):
pass
def process_response(self, request, response):
pass
def nav_title(self):
return _('Templates')
def nav_subtitle(self):
return "%d rendered" % len(self.templates)
def title(self):
return _('Templates')
def url(self):
return ''
def content(self):
return self.render('panels/template.html', {
'templates': self.templates
})
@@ -0,0 +1,22 @@
{% if templates %}
<table>
<thead>
<tr>
<th>Filename</th>
<th>Context vars</th>
</tr>
</thead>
<tbody>
{% for template in templates %}
<tr class="{{ loop.cycle('fjDebugOdd' 'fjDebugEven') }}">
<td>{{ template.template.name }}</td>
<td>{{ template.context.keys()|join(', ') }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>No templates rendered.</p>
{% endif %}
+1
View File
@@ -15,6 +15,7 @@ class DebugToolbar(object):
'flaskext.debugtoolbar.panels.timer.TimerDebugPanel',
'flaskext.debugtoolbar.panels.headers.HeaderDebugPanel',
'flaskext.debugtoolbar.panels.request_vars.RequestVarsDebugPanel',
'flaskext.debugtoolbar.panels.template.TemplateDebugPanel',
'flaskext.debugtoolbar.panels.sqlalchemy.SQLAlchemyDebugPanel',
'flaskext.debugtoolbar.panels.logger.LoggingPanel',
]