Fixes #4737: Introduce ColoredLabelColumn for consistent display of colored labels

This commit is contained in:
Jeremy Stretch
2020-06-10 11:38:23 -04:00
parent 16cdf3006f
commit 9abc67bbeb
4 changed files with 23 additions and 28 deletions

View File

@@ -84,6 +84,10 @@ class BaseTable(tables.Table):
return [name for name in self.sequence if self.columns[name].visible]
#
# Table columns
#
class ToggleColumn(tables.CheckBoxColumn):
"""
Extend CheckBoxColumn to add a "toggle all" checkbox in the column header.
@@ -129,6 +133,19 @@ class ColorColumn(tables.Column):
)
class ColoredLabelColumn(tables.TemplateColumn):
"""
Render a colored label (e.g. for DeviceRoles).
"""
template_code = """
{% load helpers %}
{% if value %}<label class="label" style="color: {{ value.color|fgcolor }}; background-color: #{{ value.color }}">{{ value }}</label>{% else %}&mdash;{% endif %}
"""
def __init__(self, *args, **kwargs):
super().__init__(template_code=self.template_code, *args, **kwargs)
class TagColumn(tables.TemplateColumn):
"""
Display a list of tags assigned to the object.