mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Added cable filter form
This commit is contained in:
@ -13,7 +13,7 @@ from .constants import (
|
||||
WIRELESS_IFACE_TYPES,
|
||||
)
|
||||
from .models import (
|
||||
ConsolePort, ConsolePortTemplate, ConsoleServerPort, ConsoleServerPortTemplate, Device, DeviceBay,
|
||||
Cable, ConsolePort, ConsolePortTemplate, ConsoleServerPort, ConsoleServerPortTemplate, Device, DeviceBay,
|
||||
DeviceBayTemplate, DeviceRole, DeviceType, FrontPanelPort, FrontPanelPortTemplate, Interface, InterfaceTemplate,
|
||||
InventoryItem, Manufacturer, Platform, PowerOutlet, PowerOutletTemplate, PowerPort, PowerPortTemplate, Rack,
|
||||
RackGroup, RackReservation, RackRole, RearPanelPort, RearPanelPortTemplate, Region, Site, VirtualChassis,
|
||||
@ -785,6 +785,13 @@ class VirtualChassisFilter(django_filters.FilterSet):
|
||||
return queryset.filter(qs_filter)
|
||||
|
||||
|
||||
class CableFilter(django_filters.FilterSet):
|
||||
|
||||
class Meta:
|
||||
model = Cable
|
||||
fields = ['type', 'status', 'color']
|
||||
|
||||
|
||||
class ConsoleConnectionFilter(django_filters.FilterSet):
|
||||
site = django_filters.CharFilter(
|
||||
method='filter_site',
|
||||
|
@ -17,10 +17,11 @@ from tenancy.forms import TenancyForm
|
||||
from tenancy.models import Tenant
|
||||
from utilities.forms import (
|
||||
AnnotatedMultipleChoiceField, APISelect, add_blank_choice, ArrayFieldSelectMultiple, BootstrapMixin, BulkEditForm,
|
||||
BulkEditNullBooleanSelect, ChainedFieldsMixin, ChainedModelChoiceField, CommentField, ComponentForm,
|
||||
ConfirmationForm, CSVChoiceField, ExpandableNameField, FilterChoiceField, FilterTreeNodeMultipleChoiceField,
|
||||
FlexibleModelChoiceField, JSONField, Livesearch, SelectWithDisabled, SelectWithPK, SmallTextarea, SlugField,
|
||||
ContentTypeSelect
|
||||
BulkEditNullBooleanSelect, ChainedFieldsMixin, ChainedModelChoiceField, ColorSelect, CommentField, ComponentForm,
|
||||
ConfirmationForm, ContentTypeSelect, CSVChoiceField, ExpandableNameField, FilterChoiceField,
|
||||
FilterTreeNodeMultipleChoiceField, FlexibleModelChoiceField, JSONField, Livesearch, SelectWithPK, SmallTextarea,
|
||||
SlugField, COLOR_CHOICES,
|
||||
|
||||
)
|
||||
from virtualization.models import Cluster
|
||||
from .constants import *
|
||||
@ -2212,6 +2213,22 @@ class CableForm(BootstrapMixin, ChainedFieldsMixin, forms.ModelForm):
|
||||
)
|
||||
|
||||
|
||||
class CableFilterForm(BootstrapMixin, forms.Form):
|
||||
model = Cable
|
||||
q = forms.CharField(required=False, label='Search')
|
||||
type = AnnotatedMultipleChoiceField(
|
||||
choices=CABLE_TYPE_CHOICES,
|
||||
annotate=Cable.objects.all(),
|
||||
annotate_field='type',
|
||||
required=False
|
||||
)
|
||||
color = forms.ChoiceField(
|
||||
choices=add_blank_choice(COLOR_CHOICES),
|
||||
widget=ColorSelect(),
|
||||
required=False
|
||||
)
|
||||
|
||||
|
||||
#
|
||||
# Device bays
|
||||
#
|
||||
|
@ -621,35 +621,39 @@ class DeviceBayTable(BaseTable):
|
||||
#
|
||||
|
||||
class CableTable(BaseTable):
|
||||
# django-tables2 adds CSS `class="label"` which causes rendering issues
|
||||
_label = tables.Column(
|
||||
accessor=Accessor('label'),
|
||||
verbose_name='Label'
|
||||
)
|
||||
device_a = tables.LinkColumn(
|
||||
viewname='dcim:device',
|
||||
accessor=Accessor('termination_a.device'),
|
||||
args=[Accessor('termination_a.device.pk')],
|
||||
orderable=False,
|
||||
verbose_name='Device A'
|
||||
)
|
||||
termination_a = tables.Column(
|
||||
accessor=Accessor('termination_a.name'),
|
||||
orderable=False,
|
||||
verbose_name='Component'
|
||||
)
|
||||
device_b = tables.LinkColumn(
|
||||
viewname='dcim:device',
|
||||
accessor=Accessor('termination_b.device'),
|
||||
args=[Accessor('termination_b.device.pk')],
|
||||
orderable=False,
|
||||
verbose_name='Device B'
|
||||
)
|
||||
termination_b = tables.Column(
|
||||
accessor=Accessor('termination_b.name'),
|
||||
orderable=False,
|
||||
verbose_name='Component'
|
||||
)
|
||||
# django-tables2 adds CSS `class="label"` which causes rendering issues
|
||||
_label = tables.Column(
|
||||
accessor=Accessor('label'),
|
||||
verbose_name='Label'
|
||||
)
|
||||
|
||||
class Meta(BaseTable.Meta):
|
||||
model = Cable
|
||||
fields = ('device_a', 'termination_a', 'device_b', 'termination_b', 'status', '_label', 'color')
|
||||
fields = ('_label', 'device_a', 'termination_a', 'device_b', 'termination_b', 'status', 'type', 'color')
|
||||
|
||||
|
||||
#
|
||||
|
@ -2017,8 +2017,8 @@ class CableListView(ObjectListView):
|
||||
queryset = Cable.objects.prefetch_related(
|
||||
'termination_a__device', 'termination_b__device'
|
||||
)
|
||||
# filter = filters.CableFilter
|
||||
# filter_form = forms.CableFilterForm
|
||||
filter = filters.CableFilter
|
||||
filter_form = forms.CableFilterForm
|
||||
table = tables.CableTable
|
||||
template_name = 'dcim/cable_list.html'
|
||||
|
||||
|
Reference in New Issue
Block a user