-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: instrument the jinja render function (more)
It instruments the single template render, but not the inherited templates and I'm guessing not the included templates either. I suspect we're going to have to patch jinja templates more robustly than relying on the django jinja backend template class.
- Loading branch information
1 parent
1f3a6dc
commit d57985d
Showing
2 changed files
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import functools | ||
|
||
from django.template.backends.jinja2 import Template as JinjaTemplate | ||
from django.template.context import make_context | ||
from django.test.signals import template_rendered | ||
|
||
|
||
def patch_jinja_render(): | ||
orig_render = JinjaTemplate.render | ||
|
||
@functools.wraps(orig_render) | ||
def wrapped_render(self, context=None, request=None): | ||
print(self.template.name) | ||
self.name = self.template.name | ||
template_rendered.send( | ||
sender=self, template=self, context=make_context(context, request) | ||
) | ||
return orig_render(self, context, request) | ||
|
||
if JinjaTemplate.render != wrapped_render: | ||
JinjaTemplate.original_render = JinjaTemplate.render | ||
JinjaTemplate.render = wrapped_render |
This file contains 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