mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-23 16:06:43 -06:00
10769 allow filtering of cables if have terminations
This commit is contained in:
parent
786f0cc7f3
commit
d56b29e502
@ -1745,6 +1745,14 @@ class CableFilterSet(TenancyFilterSet, NetBoxModelFilterSet):
|
|||||||
method='filter_by_cable_end_b',
|
method='filter_by_cable_end_b',
|
||||||
field_name='terminations__termination_id'
|
field_name='terminations__termination_id'
|
||||||
)
|
)
|
||||||
|
has_a_terminations = django_filters.BooleanFilter(
|
||||||
|
method='_has_a_terminations',
|
||||||
|
label=_('Has a terminations'),
|
||||||
|
)
|
||||||
|
has_b_terminations = django_filters.BooleanFilter(
|
||||||
|
method='_has_b_terminations',
|
||||||
|
label=_('Has b terminations'),
|
||||||
|
)
|
||||||
type = django_filters.MultipleChoiceFilter(
|
type = django_filters.MultipleChoiceFilter(
|
||||||
choices=CableTypeChoices
|
choices=CableTypeChoices
|
||||||
)
|
)
|
||||||
@ -1812,6 +1820,18 @@ class CableFilterSet(TenancyFilterSet, NetBoxModelFilterSet):
|
|||||||
# Filter by termination id and cable_end type
|
# Filter by termination id and cable_end type
|
||||||
return self.filter_by_cable_end(queryset, name, value, CableEndChoices.SIDE_B)
|
return self.filter_by_cable_end(queryset, name, value, CableEndChoices.SIDE_B)
|
||||||
|
|
||||||
|
def _has_a_terminations(self, queryset, name, value):
|
||||||
|
if value:
|
||||||
|
return queryset.filter(terminations__cable_end=CableEndChoices.SIDE_A)
|
||||||
|
else:
|
||||||
|
return queryset.exclude(terminations__cable_end=CableEndChoices.SIDE_A)
|
||||||
|
|
||||||
|
def _has_b_terminations(self, queryset, name, value):
|
||||||
|
if value:
|
||||||
|
return queryset.filter(terminations__cable_end=CableEndChoices.SIDE_B)
|
||||||
|
else:
|
||||||
|
return queryset.exclude(terminations__cable_end=CableEndChoices.SIDE_B)
|
||||||
|
|
||||||
|
|
||||||
class CableTerminationFilterSet(BaseFilterSet):
|
class CableTerminationFilterSet(BaseFilterSet):
|
||||||
termination_type = ContentTypeFilter()
|
termination_type = ContentTypeFilter()
|
||||||
|
@ -908,7 +908,7 @@ class VirtualChassisFilterForm(TenancyFilterForm, NetBoxModelFilterSetForm):
|
|||||||
class CableFilterForm(TenancyFilterForm, NetBoxModelFilterSetForm):
|
class CableFilterForm(TenancyFilterForm, NetBoxModelFilterSetForm):
|
||||||
model = Cable
|
model = Cable
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
(None, ('q', 'filter_id', 'tag')),
|
(None, ('q', 'filter_id', 'has_a_terminations', 'has_b_terminations', 'tag')),
|
||||||
(_('Location'), ('site_id', 'location_id', 'rack_id', 'device_id')),
|
(_('Location'), ('site_id', 'location_id', 'rack_id', 'device_id')),
|
||||||
(_('Attributes'), ('type', 'status', 'color', 'length', 'length_unit')),
|
(_('Attributes'), ('type', 'status', 'color', 'length', 'length_unit')),
|
||||||
(_('Tenant'), ('tenant_group_id', 'tenant_id')),
|
(_('Tenant'), ('tenant_group_id', 'tenant_id')),
|
||||||
@ -979,6 +979,20 @@ class CableFilterForm(TenancyFilterForm, NetBoxModelFilterSetForm):
|
|||||||
choices=add_blank_choice(CableLengthUnitChoices),
|
choices=add_blank_choice(CableLengthUnitChoices),
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
|
has_a_terminations = forms.NullBooleanField(
|
||||||
|
label=_('Has a terminations'),
|
||||||
|
required=False,
|
||||||
|
widget=forms.Select(
|
||||||
|
choices=BOOLEAN_WITH_BLANK_CHOICES
|
||||||
|
)
|
||||||
|
)
|
||||||
|
has_b_terminations = forms.NullBooleanField(
|
||||||
|
label=_('Has b terminations'),
|
||||||
|
required=False,
|
||||||
|
widget=forms.Select(
|
||||||
|
choices=BOOLEAN_WITH_BLANK_CHOICES
|
||||||
|
)
|
||||||
|
)
|
||||||
tag = TagFilterField(model)
|
tag = TagFilterField(model)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user