Created
March 13, 2011 12:44
-
-
Save dcramer/868061 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from threading import local | |
_blah = local() | |
class StopThatShit(Exception): | |
pass | |
def patch(): | |
from django.db.backends import util | |
from django import template | |
class StopQueryingCursorWrapper(util.CursorWrapper): | |
def __init__(self, cursor, connection): | |
if getattr(_blah, 'rendering', False): | |
raise StopThatShit('Stop executing queries in your templates!') | |
super(StopQueryingCursorWrapper, self).__init__(cursor, connection) | |
util.CursorWrapper = StopQueryingCursorWrapper | |
class StopQueryingTemplate(template.Template): | |
def render(self, context): | |
_blah.rendering = True | |
try: | |
super(StopQueryingTemplate, self).__init__(context) | |
finally: | |
_blah.rendering = False | |
template.Template = StopQueryingTemplate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment