Package madrona :: Package common :: Module middleware
[hide private]

Source Code for Module madrona.common.middleware

 1  from django.db import connection 
 2  from django.template import Template, Context 
 3  from django.conf import settings 
 4   
 5  # 
 6  # Log all SQL statements direct to the console (when running in DEBUG) 
 7  # Intended for use with the django development server. 
 8  # 
 9   
10 -class SQLLogToConsoleMiddleware:
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 """
20 - def process_response(self, request, response):
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
27 -class IgnoreCsrfMiddleware(object):
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 """
34 - def process_request(self, request):
35 request.csrf_processing_done = True
36