-
Notifications
You must be signed in to change notification settings - Fork 437
Description
I previously suggested a way of making ´TemplateColumn` more flexible in #928, but I think that stalled out with #931, and was possibly more complicated than warranted. (Or rather, everybody who needs an extra context can go and implement it as a subclass of TemplateColumn, like I did.)
However, once issue I came up again is that TemplateColumn does not pass the request to the context when rendering a template.
This is – surprisingly to me – not really solvable purely by subclassing, or rather, you have to reimplement the full render method. That's because some template tags, like for example querystring, access Context.request directly. However, as the context passed to the template is context.flatten() (that is, a dictionary), you cannot use {% querystring %} in TemplateColumn.
The required change would be small:
- return get_template(self.template_name).render(context.flatten())
+ return get_template(self.template_name).render(context.flatten(), request=getattr(table, request, None))When .render() is called with a request parameter, it will pass the request on to make_context, which will then set the request attribute on the resulting context.