-
Notifications
You must be signed in to change notification settings - Fork 429
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add context arguments to TemplateColumn #509
Conversation
@ad-m Nice idea, could be very useful! At first thought I'd suggest renaming the context argument to |
@jieter , you are right. Fix'd. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the change. I've added some other comments, will merge when those are addressed.
@@ -18,6 +18,7 @@ class TemplateColumn(Column): | |||
Arguments: | |||
template_code (str): template code to render | |||
template_name (str): name of the template to render | |||
extra_context (dict): template variables used to (optional) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sentence seems to be incomplete.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jieter , Can you suggest a full content of line? I do not know enough English to do it myself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about:
extra_content (dict): optional extra template context.
@@ -26,24 +27,27 @@ class TemplateColumn(Column): | |||
- *value* -- value from `record` that corresponds to the current column | |||
- *default* -- appropriate default value to use as fallback | |||
- *row_counter* -- The number of the row this cell is being rendered in. | |||
- context variables pass as argument to column |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this one too. Also: please use the same style as the other list items.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed the style because the keys are listed before, and here the value of the context key is dynamic. No static keys of context, so no bold.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, makes sense! I would propose:
- any context variables passed using the `extra_context` argument to `TemplateColumn`.
|
||
Example: | ||
|
||
.. code-block:: python | ||
|
||
class ExampleTable(tables.Table): | ||
foo = tables.TemplateColumn('{{ record.bar }}') | ||
# contents of `myapp/bar_column.html` is `{{ value }}` | ||
bar = tables.TemplateColumn(template_name='myapp/name2_column.html') | ||
# contents of `myapp/bar_column.html` is `{{label}}: {{ value }}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add spaces around label
to get consistent style with the other template variables in the example?
@jieter , changes introduced. Thank you for your comments and help. |
@ad-m thanks for the changes. As the final piece of the puzzle, It would be nice if you could add a test case checking for the extra context to be present. |
@ad-m thanks, merged! |
Hello,
I suggest add argument to TemplateColumn. This is important to ensure effective re-use of templates as in following example.
Example template:
Example table: