annotate mysite/sqllog.py @ 14:54e35b21b369

Fix typo in slideshow div id.
author Brian Neal <bgneal@gmail.com>
date Sun, 29 Aug 2010 18:43:15 +0000
parents 0dcfcdf50c62
children
rev   line source
bgneal@1 1 from django.db import connection
bgneal@1 2 from django.template import Template, Context
bgneal@1 3
bgneal@1 4 class SQLLogMiddleware:
bgneal@1 5
bgneal@1 6 def process_response ( self, request, response ):
bgneal@1 7 time = 0.0
bgneal@1 8 for q in connection.queries:
bgneal@1 9 time += float(q['time'])
bgneal@1 10 t = Template('''
bgneal@1 11 <p><em>Total query count:</em> {{ count }}<br/>
bgneal@1 12 <em>Total execution time:</em> {{ time }}</p>
bgneal@1 13 <ol class="sqllog">
bgneal@1 14 {% for sql in sqllog %}
bgneal@1 15 <li>{{ sql.time }}: {{ sql.sql }}</li>
bgneal@1 16 {% endfor %}
bgneal@1 17 </ol>
bgneal@1 18 ''')
bgneal@1 19 response.content = "%s%s" % ( response.content, t.render(Context({'sqllog':connection.queries,'count':len(connection.queries),'time':time})))
bgneal@1 20 return response