mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 20:12:00 -06:00
Added device status filter and table column
This commit is contained in:
parent
950a6ea7b2
commit
91a5b2eb5f
@ -148,6 +148,10 @@ class DeviceFilter(django_filters.FilterSet):
|
||||
to_field_name='slug',
|
||||
label='Platform (slug)',
|
||||
)
|
||||
status = django_filters.BooleanFilter(
|
||||
name='status',
|
||||
label='Status',
|
||||
)
|
||||
is_console_server = django_filters.BooleanFilter(
|
||||
name='device_type__is_console_server',
|
||||
label='Is a console server',
|
||||
@ -164,7 +168,7 @@ class DeviceFilter(django_filters.FilterSet):
|
||||
class Meta:
|
||||
model = Device
|
||||
fields = ['q', 'name', 'site_id', 'site', 'rack_id', 'role_id', 'role', 'device_type_id', 'manufacturer_id',
|
||||
'manufacturer', 'model', 'platform_id', 'platform', 'is_console_server', 'is_pdu',
|
||||
'manufacturer', 'model', 'platform_id', 'platform', 'status', 'is_console_server', 'is_pdu',
|
||||
'is_network_device']
|
||||
|
||||
def search(self, queryset, value):
|
||||
|
@ -13,10 +13,10 @@ from .models import Site, Rack, RackGroup, Device, Manufacturer, DeviceType, Dev
|
||||
CONNECTION_STATUS_PLANNED, CONNECTION_STATUS_CONNECTED, IFACE_FF_VIRTUAL, STATUS_CHOICES
|
||||
|
||||
|
||||
BULK_STATUS_CHOICES = [
|
||||
FORM_STATUS_CHOICES = [
|
||||
['', '---------'],
|
||||
]
|
||||
BULK_STATUS_CHOICES += STATUS_CHOICES
|
||||
FORM_STATUS_CHOICES += STATUS_CHOICES
|
||||
|
||||
DEVICE_BY_PK_RE = '{\d+\}'
|
||||
|
||||
@ -411,7 +411,7 @@ class DeviceBulkEditForm(forms.Form, BootstrapMixin):
|
||||
device_role = forms.ModelChoiceField(queryset=DeviceRole.objects.all(), required=False, label='Role')
|
||||
platform = forms.ModelChoiceField(queryset=Platform.objects.all(), required=False, label='Platform')
|
||||
platform_delete = forms.BooleanField(required=False, label='Set platform to "none"')
|
||||
status = forms.ChoiceField(choices=BULK_STATUS_CHOICES, required=False, initial='', label='Status')
|
||||
status = forms.ChoiceField(choices=FORM_STATUS_CHOICES, required=False, initial='', label='Status')
|
||||
serial = forms.CharField(max_length=50, required=False, label='Serial Number')
|
||||
ro_snmp = forms.CharField(max_length=50, required=False, label='SNMP (RO)')
|
||||
|
||||
@ -448,6 +448,7 @@ class DeviceFilterForm(forms.Form, BootstrapMixin):
|
||||
device_type_id = forms.MultipleChoiceField(required=False, choices=device_type_choices, label='Type',
|
||||
widget=forms.SelectMultiple(attrs={'size': 8}))
|
||||
platform = forms.MultipleChoiceField(required=False, choices=device_platform_choices)
|
||||
status = forms.NullBooleanField(required=False, widget=forms.Select(choices=FORM_STATUS_CHOICES))
|
||||
|
||||
|
||||
#
|
||||
|
@ -12,6 +12,10 @@ RACKGROUP_EDIT_LINK = """
|
||||
<a href="{% url 'dcim:rackgroup_edit' pk=record.pk %}">Edit</a>
|
||||
"""
|
||||
|
||||
STATUS_ICON = """
|
||||
<span class="glyphicon glyphicon-{% if record.status %}ok-sign text-success" title="Active{% else %}minus-sign text-danger" title="Offline{% endif %}" aria-hidden="true"></span>
|
||||
"""
|
||||
|
||||
|
||||
#
|
||||
# Sites
|
||||
@ -220,13 +224,12 @@ class InterfaceTemplateBulkDeleteTable(InterfaceTemplateTable):
|
||||
fields = ('pk', 'name')
|
||||
|
||||
|
||||
|
||||
|
||||
#
|
||||
# Devices
|
||||
#
|
||||
|
||||
class DeviceTable(tables.Table):
|
||||
status = tables.TemplateColumn(template_code=STATUS_ICON, verbose_name='')
|
||||
name = tables.TemplateColumn(template_code=DEVICE_LINK, verbose_name='Name')
|
||||
site = tables.Column(accessor=Accessor('rack.site'), verbose_name='Site')
|
||||
rack = tables.LinkColumn('dcim:rack', args=[Accessor('rack.pk')], verbose_name='Rack')
|
||||
@ -236,7 +239,7 @@ class DeviceTable(tables.Table):
|
||||
|
||||
class Meta:
|
||||
model = Device
|
||||
fields = ('name', 'site', 'rack', 'device_role', 'device_type', 'primary_ip')
|
||||
fields = ('name', 'status', 'site', 'rack', 'device_role', 'device_type', 'primary_ip')
|
||||
empty_text = "No devices were found."
|
||||
attrs = {
|
||||
'class': 'table table-hover',
|
||||
@ -248,7 +251,7 @@ class DeviceBulkEditTable(DeviceTable):
|
||||
|
||||
class Meta(DeviceTable.Meta):
|
||||
model = None # django_tables2 bugfix
|
||||
fields = ('pk', 'name', 'site', 'rack', 'device_role', 'device_type', 'primary_ip')
|
||||
fields = ('pk', 'name', 'status', 'site', 'rack', 'device_role', 'device_type', 'primary_ip')
|
||||
|
||||
|
||||
class DeviceImportTable(tables.Table):
|
||||
|
Loading…
Reference in New Issue
Block a user