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

@ -4,7 +4,7 @@ import django_tables2 as tables
from django_tables2.utils import Accessor from django_tables2.utils import Accessor
from tenancy.tables import COL_TENANT from tenancy.tables import COL_TENANT
from utilities.tables import BaseTable, ToggleColumn from utilities.tables import BaseTable, BooleanColumn, ToggleColumn
from .models import ( from .models import (
ConsolePort, ConsolePortTemplate, ConsoleServerPort, ConsoleServerPortTemplate, Device, DeviceBay, ConsolePort, ConsolePortTemplate, ConsoleServerPort, ConsoleServerPortTemplate, Device, DeviceBay,
DeviceBayTemplate, DeviceRole, DeviceType, Interface, InterfaceTemplate, InventoryItem, Manufacturer, Platform, DeviceBayTemplate, DeviceRole, DeviceType, Interface, InterfaceTemplate, InventoryItem, Manufacturer, Platform,
@ -346,10 +346,10 @@ class DeviceTypeTable(BaseTable):
args=[Accessor('pk')], args=[Accessor('pk')],
verbose_name='Device Type' verbose_name='Device Type'
) )
is_full_depth = tables.BooleanColumn(verbose_name='Full Depth') is_full_depth = BooleanColumn(verbose_name='Full Depth')
is_console_server = tables.BooleanColumn(verbose_name='CS') is_console_server = BooleanColumn(verbose_name='CS')
is_pdu = tables.BooleanColumn(verbose_name='PDU') is_pdu = BooleanColumn(verbose_name='PDU')
is_network_device = tables.BooleanColumn(verbose_name='Net') is_network_device = BooleanColumn(verbose_name='Net')
subdevice_role = tables.TemplateColumn( subdevice_role = tables.TemplateColumn(
template_code=SUBDEVICE_ROLE_TEMPLATE, template_code=SUBDEVICE_ROLE_TEMPLATE,
verbose_name='Subdevice Role' verbose_name='Subdevice Role'

View File

@ -3,7 +3,7 @@ from __future__ import unicode_literals
import django_tables2 as tables import django_tables2 as tables
from taggit.models import Tag from taggit.models import Tag
from utilities.tables import BaseTable, ToggleColumn from utilities.tables import BaseTable, BooleanColumn, ToggleColumn
from .models import ConfigContext, ObjectChange from .models import ConfigContext, ObjectChange
TAG_ACTIONS = """ TAG_ACTIONS = """
@ -59,7 +59,7 @@ class TagTable(BaseTable):
class ConfigContextTable(BaseTable): class ConfigContextTable(BaseTable):
pk = ToggleColumn() pk = ToggleColumn()
name = tables.LinkColumn() name = tables.LinkColumn()
is_active = tables.BooleanColumn( is_active = BooleanColumn(
verbose_name='Active' verbose_name='Active'
) )
actions = tables.TemplateColumn( actions = tables.TemplateColumn(

View File

@ -5,7 +5,7 @@ from django_tables2.utils import Accessor
from dcim.models import Interface from dcim.models import Interface
from tenancy.tables import COL_TENANT from tenancy.tables import COL_TENANT
from utilities.tables import BaseTable, ToggleColumn from utilities.tables import BaseTable, BooleanColumn, ToggleColumn
from .models import Aggregate, IPAddress, Prefix, RIR, Role, Service, VLAN, VLANGroup, VRF from .models import Aggregate, IPAddress, Prefix, RIR, Role, Service, VLAN, VLANGroup, VRF
RIR_UTILIZATION = """ RIR_UTILIZATION = """
@ -193,7 +193,7 @@ class VRFTable(BaseTable):
class RIRTable(BaseTable): class RIRTable(BaseTable):
pk = ToggleColumn() pk = ToggleColumn()
name = tables.LinkColumn(verbose_name='Name') name = tables.LinkColumn(verbose_name='Name')
is_private = tables.BooleanColumn(verbose_name='Private') is_private = BooleanColumn(verbose_name='Private')
aggregate_count = tables.Column(verbose_name='Aggregates') aggregate_count = tables.Column(verbose_name='Aggregates')
actions = tables.TemplateColumn(template_code=RIR_ACTIONS, attrs={'td': {'class': 'text-right'}}, verbose_name='') actions = tables.TemplateColumn(template_code=RIR_ACTIONS, attrs={'td': {'class': 'text-right'}}, verbose_name='')

View File

@ -31,3 +31,18 @@ class ToggleColumn(tables.CheckBoxColumn):
@property @property
def header(self): def header(self):
return mark_safe('<input type="checkbox" class="toggle" title="Toggle all" />') 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)