Mercurial > public > madeira
view mysite/sqllog.py @ 88:7245c769e31e django1.3
Close this branch. I'm not sure if I merged it correctly to the
default branch, because the graphlog doesn't look right. But the
changes were made to default somehow. So closing this off to prevent
future confusion.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 13 Apr 2013 18:08:19 -0500 |
parents | 0dcfcdf50c62 |
children |
line wrap: on
line source
from django.db import connection from django.template import Template, Context class SQLLogMiddleware: def process_response ( self, request, response ): time = 0.0 for q in connection.queries: time += float(q['time']) t = Template(''' <p><em>Total query count:</em> {{ count }}<br/> <em>Total execution time:</em> {{ time }}</p> <ol class="sqllog"> {% for sql in sqllog %} <li>{{ sql.time }}: {{ sql.sql }}</li> {% endfor %} </ol> ''') response.content = "%s%s" % ( response.content, t.render(Context({'sqllog':connection.queries,'count':len(connection.queries),'time':time}))) return response