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:
@ -4,7 +4,7 @@ import django_tables2 as tables
|
||||
from django_tables2.utils import Accessor
|
||||
|
||||
from tenancy.tables import COL_TENANT
|
||||
from utilities.tables import BaseTable, ToggleColumn
|
||||
from utilities.tables import BaseTable, BooleanColumn, ToggleColumn
|
||||
from .models import (
|
||||
ConsolePort, ConsolePortTemplate, ConsoleServerPort, ConsoleServerPortTemplate, Device, DeviceBay,
|
||||
DeviceBayTemplate, DeviceRole, DeviceType, Interface, InterfaceTemplate, InventoryItem, Manufacturer, Platform,
|
||||
@ -346,10 +346,10 @@ class DeviceTypeTable(BaseTable):
|
||||
args=[Accessor('pk')],
|
||||
verbose_name='Device Type'
|
||||
)
|
||||
is_full_depth = tables.BooleanColumn(verbose_name='Full Depth')
|
||||
is_console_server = tables.BooleanColumn(verbose_name='CS')
|
||||
is_pdu = tables.BooleanColumn(verbose_name='PDU')
|
||||
is_network_device = tables.BooleanColumn(verbose_name='Net')
|
||||
is_full_depth = BooleanColumn(verbose_name='Full Depth')
|
||||
is_console_server = BooleanColumn(verbose_name='CS')
|
||||
is_pdu = BooleanColumn(verbose_name='PDU')
|
||||
is_network_device = BooleanColumn(verbose_name='Net')
|
||||
subdevice_role = tables.TemplateColumn(
|
||||
template_code=SUBDEVICE_ROLE_TEMPLATE,
|
||||
verbose_name='Subdevice Role'
|
||||
|
@ -3,7 +3,7 @@ from __future__ import unicode_literals
|
||||
import django_tables2 as tables
|
||||
from taggit.models import Tag
|
||||
|
||||
from utilities.tables import BaseTable, ToggleColumn
|
||||
from utilities.tables import BaseTable, BooleanColumn, ToggleColumn
|
||||
from .models import ConfigContext, ObjectChange
|
||||
|
||||
TAG_ACTIONS = """
|
||||
@ -59,7 +59,7 @@ class TagTable(BaseTable):
|
||||
class ConfigContextTable(BaseTable):
|
||||
pk = ToggleColumn()
|
||||
name = tables.LinkColumn()
|
||||
is_active = tables.BooleanColumn(
|
||||
is_active = BooleanColumn(
|
||||
verbose_name='Active'
|
||||
)
|
||||
actions = tables.TemplateColumn(
|
||||
|
@ -5,7 +5,7 @@ from django_tables2.utils import Accessor
|
||||
|
||||
from dcim.models import Interface
|
||||
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
|
||||
|
||||
RIR_UTILIZATION = """
|
||||
@ -193,7 +193,7 @@ class VRFTable(BaseTable):
|
||||
class RIRTable(BaseTable):
|
||||
pk = ToggleColumn()
|
||||
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')
|
||||
actions = tables.TemplateColumn(template_code=RIR_ACTIONS, attrs={'td': {'class': 'text-right'}}, verbose_name='')
|
||||
|
||||
|
@ -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">—</span>'
|
||||
return mark_safe(rendered)
|
||||
|
Reference in New Issue
Block a user