1 from django.db import connection
2 from django.template import Template, Context
3 from django.conf import settings
4
5
6
7
8
9
11 """
12 Add to settings_local like so to log sql commands:
13
14 from madrona.common.default_settings import MIDDLEWARE_CLASSES
15
16 MIDDLEWARE_CLASSES += (
17 'madrona.common.middleware.SQLLogToConsoleMiddleware',
18 )
19 """
21 if settings.DEBUG and connection.queries:
22 time = sum([float(q['time']) for q in connection.queries])
23 t = Template("{{count}} quer{{count|pluralize:\"y,ies\"}} in {{time}} seconds:\n\n{% for sql in sqllog %}[{{forloop.counter}}] {{sql.time}}s: {{sql.sql|safe}}{% if not forloop.last %}\n\n{% endif %}{% endfor %}")
24 print t.render(Context({'sqllog':connection.queries,'count':len(connection.queries),'time':time}))
25 return response
26
28 """
29 http://djangosnippets.org/snippets/2069/
30 CSRF protection requires updating all forms
31 Meanwhile the crsf middleware is required for admin to work.
32 This middleware class will just ignore csrf, allowing the current views and admin to work
33 """
35 request.csrf_processing_done = True
36