Skip to content

Commit

Permalink
Fix popping the extra_context of TemplateColumn (#767)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernhard Miller authored Sep 14, 2020
1 parent 5c47d04 commit 99ee0ef
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions django_tables2/columns/templatecolumn.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,19 @@ def render(self, record, table, value, bound_column, **kwargs):
# If the table is being rendered using `render_table`, it hackily
# attaches the context to the table as a gift to `TemplateColumn`.
context = getattr(table, "context", Context())
context.update(self.extra_context)
context.update(
{
"default": bound_column.default,
"column": bound_column,
"record": record,
"value": value,
"row_counter": kwargs["bound_row"].row_counter,
}
)

try:
additional_context = {
"default": bound_column.default,
"column": bound_column,
"record": record,
"value": value,
"row_counter": kwargs["bound_row"].row_counter,
}
additional_context.update(self.extra_context)
with context.update(additional_context):
if self.template_code:
return Template(self.template_code).render(context)
else:
return get_template(self.template_name).render(context.flatten())
finally:
context.pop()

def value(self, **kwargs):
"""
Expand Down

0 comments on commit 99ee0ef

Please sign in to comment.