jbalogh/jingo — pull request #55 by peterbe (2014-04-14 22:02:50+00:00)
Title: load helpers from monkey

@jbalogh r?

tox still passes happily. And I tried this out in various ways on mozilla/airmozilla and this patch works. Unfortunately I was not able to reproduce [the original problem](https://groups.google.com/d/msg/mozilla.dev.webdev/uyeh-CKt8MY/GIp-GKmV1fwJ) locally.

The problem is that `load_helpers()` is called on every `Environment.get_template()` and `Environment.from_string()`. I suspect this is done here so it can be done really really late and thus make sure all apps have been installed. Because of the excessive calls a non-thread-safe device is put in place using a global variable. That's premature optimization I think.

The reason why it makes sense to do this from `monkey.py` is because, in django, `jingo.monkey` is (at least should be) called from the root `urls.py` which is only invoked by Django AFTER all apps have successfully been installed.