def render_query_table(queries): """Renders a nice table of all queries in the page.""" total = 0 qresult = [] for statement, parameters, start, end, calling_context in queries: total += (end - start) qresult.append(u'<li><pre>%s</pre><pre>Parameters: %s</pre>' u'<div class="detail"><em>%s</em> | ' u'<strong>took %.3f ms</strong></div></li>' % ( statement, parameters, escape(calling_context), (end - start) * 1000 )) result = [u'<div id="database_debug_table">'] stat = (u'<strong>(%d queries in %.2f ms)</strong>' % (len(queries), total * 1000)) result.append(stat) result.append(u'<div id="database_debug_table_inner"><ul>') result.extend(qresult) result.append(u'<li>%s</li></ul></div></div>' % stat) result.append(html.script(""" $(document).ready(function() { function toggleLog() { $('#database_debug_table_inner').toggle(); } $('<a href="#database_debug_table">Show/Hide Log</a>').click(toggleLog) .prependTo($('#database_debug_table')); toggleLog(); }); """, type='text/javascript')) return u'\n'.join(result)
def render_query_table(queries): """Renders a nice table of all queries in the page.""" total = 0 qresult = [] for statement, parameters, start, end, calling_context in queries: total += end - start qresult.append( u"<li><pre>%s</pre><pre>Parameters: %s</pre>" u'<div class="detail"><em>%s</em> | ' u"<strong>took %.3f ms</strong></div></li>" % (statement, parameters, escape(calling_context), (end - start) * 1000) ) result = [u'<div id="database_debug_table">'] stat = u"<strong>(%d queries in %.2f ms)</strong>" % (len(queries), total * 1000) result.append(stat) result.append(u'<div id="database_debug_table_inner"><ul>') result.extend(qresult) result.append(u"<li>%s</li></ul></div></div>" % stat) result.append( html.script( """ $(document).ready(function() { function toggleLog() { $('#database_debug_table_inner').toggle(); } $('<a href="#database_debug_table">Show/Hide Log</a>').click(toggleLog) .prependTo($('#database_debug_table')); toggleLog(); }); """, type="text/javascript", ) ) return u"\n".join(result)
def script(src, type='text/javascript', **attr): """Render a script tag.""" return html.script(src=src, type=type, **attr)