1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Improved rendering of boolean fields in tables

This commit is contained in:
Jeremy Stretch
2018-06-29 12:05:56 -04:00
parent b9bdd666da
commit bf1c7cacc6
4 changed files with 24 additions and 9 deletions

View File

@ -31,3 +31,18 @@ class ToggleColumn(tables.CheckBoxColumn):
@property
def header(self):
return mark_safe('<input type="checkbox" class="toggle" title="Toggle all" />')
class BooleanColumn(tables.Column):
"""
Custom implementation of BooleanColumn to render a nicely-formatted checkmark or X icon instead of a Unicode
character.
"""
def render(self, value):
if value is True:
rendered = '<span class="text-success"><i class="fa fa-check"></i></span>'
elif value is False:
rendered = '<span class="text-danger"><i class="fa fa-close"></i></span>'
else:
rendered = '<span class="text-muted">&mdash;</span>'
return mark_safe(rendered)