mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Colorized roles in rack and device lists
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
import django_tables2 as tables
|
import django_tables2 as tables
|
||||||
from django_tables2.utils import Accessor
|
from django_tables2.utils import Accessor
|
||||||
|
|
||||||
from utilities.tables import BaseTable, ColorColumn, ToggleColumn
|
from utilities.tables import BaseTable, ToggleColumn
|
||||||
|
|
||||||
from .models import (
|
from .models import (
|
||||||
ConsolePort, ConsolePortTemplate, ConsoleServerPortTemplate, Device, DeviceBayTemplate, DeviceRole, DeviceType,
|
ConsolePort, ConsolePortTemplate, ConsoleServerPortTemplate, Device, DeviceBayTemplate, DeviceRole, DeviceType,
|
||||||
@ -10,6 +10,10 @@ from .models import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
COLOR_LABEL = """
|
||||||
|
<label class="label {{ record.color }}">{{ record }}</label>
|
||||||
|
"""
|
||||||
|
|
||||||
DEVICE_LINK = """
|
DEVICE_LINK = """
|
||||||
<a href="{% url 'dcim:device' pk=record.pk %}">
|
<a href="{% url 'dcim:device' pk=record.pk %}">
|
||||||
{{ record.name|default:'<span class="label label-info">Unnamed device</span>' }}
|
{{ record.name|default:'<span class="label label-info">Unnamed device</span>' }}
|
||||||
@ -28,6 +32,14 @@ RACKROLE_ACTIONS = """
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
RACK_ROLE = """
|
||||||
|
{% if record.role %}
|
||||||
|
<label class="label {{ record.role.color }}">{{ value }}</label>
|
||||||
|
{% else %}
|
||||||
|
—
|
||||||
|
{% endif %}
|
||||||
|
"""
|
||||||
|
|
||||||
DEVICEROLE_ACTIONS = """
|
DEVICEROLE_ACTIONS = """
|
||||||
{% if perms.dcim.change_devicerole %}
|
{% if perms.dcim.change_devicerole %}
|
||||||
<a href="{% url 'dcim:devicerole_edit' slug=record.slug %}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
|
<a href="{% url 'dcim:devicerole_edit' slug=record.slug %}" class="btn btn-xs btn-warning"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
|
||||||
@ -46,6 +58,10 @@ PLATFORM_ACTIONS = """
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
DEVICE_ROLE = """
|
||||||
|
<label class="label {{ record.device_role.color }}">{{ value }}</label>
|
||||||
|
"""
|
||||||
|
|
||||||
STATUS_ICON = """
|
STATUS_ICON = """
|
||||||
{% if record.status %}
|
{% if record.status %}
|
||||||
<span class="glyphicon glyphicon-ok-sign text-success" title="Active" aria-hidden="true"></span>
|
<span class="glyphicon glyphicon-ok-sign text-success" title="Active" aria-hidden="true"></span>
|
||||||
@ -108,7 +124,7 @@ class RackRoleTable(BaseTable):
|
|||||||
pk = ToggleColumn()
|
pk = ToggleColumn()
|
||||||
name = tables.LinkColumn(verbose_name='Name')
|
name = tables.LinkColumn(verbose_name='Name')
|
||||||
rack_count = tables.Column(verbose_name='Racks')
|
rack_count = tables.Column(verbose_name='Racks')
|
||||||
color = ColorColumn(verbose_name='Color')
|
color = tables.TemplateColumn(COLOR_LABEL, verbose_name='Color')
|
||||||
slug = tables.Column(verbose_name='Slug')
|
slug = tables.Column(verbose_name='Slug')
|
||||||
actions = tables.TemplateColumn(template_code=RACKROLE_ACTIONS, attrs={'td': {'class': 'text-right'}},
|
actions = tables.TemplateColumn(template_code=RACKROLE_ACTIONS, attrs={'td': {'class': 'text-right'}},
|
||||||
verbose_name='')
|
verbose_name='')
|
||||||
@ -129,7 +145,7 @@ class RackTable(BaseTable):
|
|||||||
group = tables.Column(accessor=Accessor('group.name'), verbose_name='Group')
|
group = tables.Column(accessor=Accessor('group.name'), verbose_name='Group')
|
||||||
facility_id = tables.Column(verbose_name='Facility ID')
|
facility_id = tables.Column(verbose_name='Facility ID')
|
||||||
tenant = tables.LinkColumn('tenancy:tenant', args=[Accessor('tenant.slug')], verbose_name='Tenant')
|
tenant = tables.LinkColumn('tenancy:tenant', args=[Accessor('tenant.slug')], verbose_name='Tenant')
|
||||||
role = tables.Column(verbose_name='Role')
|
role = tables.TemplateColumn(RACK_ROLE, verbose_name='Role')
|
||||||
u_height = tables.TemplateColumn("{{ record.u_height }}U", verbose_name='Height')
|
u_height = tables.TemplateColumn("{{ record.u_height }}U", verbose_name='Height')
|
||||||
devices = tables.Column(accessor=Accessor('device_count'), verbose_name='Devices')
|
devices = tables.Column(accessor=Accessor('device_count'), verbose_name='Devices')
|
||||||
u_consumed = tables.TemplateColumn("{{ record.u_consumed|default:'0' }}U", verbose_name='Used')
|
u_consumed = tables.TemplateColumn("{{ record.u_consumed|default:'0' }}U", verbose_name='Used')
|
||||||
@ -258,7 +274,7 @@ class DeviceRoleTable(BaseTable):
|
|||||||
pk = ToggleColumn()
|
pk = ToggleColumn()
|
||||||
name = tables.LinkColumn(verbose_name='Name')
|
name = tables.LinkColumn(verbose_name='Name')
|
||||||
device_count = tables.Column(verbose_name='Devices')
|
device_count = tables.Column(verbose_name='Devices')
|
||||||
color = ColorColumn(verbose_name='Color')
|
color = tables.TemplateColumn(COLOR_LABEL, verbose_name='Color')
|
||||||
slug = tables.Column(verbose_name='Slug')
|
slug = tables.Column(verbose_name='Slug')
|
||||||
actions = tables.TemplateColumn(template_code=DEVICEROLE_ACTIONS, attrs={'td': {'class': 'text-right'}},
|
actions = tables.TemplateColumn(template_code=DEVICEROLE_ACTIONS, attrs={'td': {'class': 'text-right'}},
|
||||||
verbose_name='')
|
verbose_name='')
|
||||||
@ -295,7 +311,7 @@ class DeviceTable(BaseTable):
|
|||||||
tenant = tables.LinkColumn('tenancy:tenant', args=[Accessor('tenant.slug')], verbose_name='Tenant')
|
tenant = tables.LinkColumn('tenancy:tenant', args=[Accessor('tenant.slug')], verbose_name='Tenant')
|
||||||
site = tables.Column(accessor=Accessor('rack.site'), verbose_name='Site')
|
site = tables.Column(accessor=Accessor('rack.site'), verbose_name='Site')
|
||||||
rack = tables.LinkColumn('dcim:rack', args=[Accessor('rack.pk')], verbose_name='Rack')
|
rack = tables.LinkColumn('dcim:rack', args=[Accessor('rack.pk')], verbose_name='Rack')
|
||||||
device_role = tables.Column(verbose_name='Role')
|
device_role = tables.TemplateColumn(DEVICE_ROLE, verbose_name='Role')
|
||||||
device_type = tables.Column(verbose_name='Type')
|
device_type = tables.Column(verbose_name='Type')
|
||||||
primary_ip = tables.TemplateColumn(orderable=False, verbose_name='IP Address',
|
primary_ip = tables.TemplateColumn(orderable=False, verbose_name='IP Address',
|
||||||
template_code="{{ record.primary_ip.address.ip }}")
|
template_code="{{ record.primary_ip.address.ip }}")
|
||||||
|
@ -87,7 +87,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>Role</td>
|
<td>Role</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="{% url 'dcim:device_list' %}?role={{ device.device_role.slug }}">{{ device.device_role }}</a>
|
<a href="{{ device.device_role.get_absolute_url }}">{{ device.device_role }}</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -96,6 +96,16 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Role</td>
|
||||||
|
<td>
|
||||||
|
{% if rack.role %}
|
||||||
|
<a href="{{ rack.role.get_absolute_url }}">{{ rack.role }}</a>
|
||||||
|
{% else %}
|
||||||
|
<span class="text-muted">None</span>
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Type</td>
|
<td>Type</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -28,10 +28,3 @@ class ToggleColumn(tables.CheckBoxColumn):
|
|||||||
@property
|
@property
|
||||||
def header(self):
|
def header(self):
|
||||||
return mark_safe('<input type="checkbox" name="_all" title="Select all" />')
|
return mark_safe('<input type="checkbox" name="_all" title="Select all" />')
|
||||||
|
|
||||||
|
|
||||||
class ColorColumn(tables.Column):
|
|
||||||
|
|
||||||
def render(self, record):
|
|
||||||
html = '<label class="label {}">{}</label>'.format(record.color, record.get_color_display())
|
|
||||||
return mark_safe(html)
|
|
||||||
|
Reference in New Issue
Block a user