Mercurial > public > madeira
annotate mysite/sqllog.py @ 2:ffef0899826e
Created apache directory to hold the madeira.wsgi file.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Fri, 10 Apr 2009 00:16:22 +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 |