mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-23 07:56:44 -06:00
10769 change to termianted
This commit is contained in:
parent
edae010837
commit
acfaa8cf4b
@ -1,5 +1,6 @@
|
||||
import django_filters
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.db.models import Q
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from extras.filtersets import LocalConfigContextFilterSet
|
||||
@ -1745,13 +1746,9 @@ class CableFilterSet(TenancyFilterSet, NetBoxModelFilterSet):
|
||||
method='filter_by_cable_end_b',
|
||||
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'),
|
||||
unterminated = django_filters.BooleanFilter(
|
||||
method='_unterminated',
|
||||
label=_('Unterminated'),
|
||||
)
|
||||
type = django_filters.MultipleChoiceFilter(
|
||||
choices=CableTypeChoices
|
||||
@ -1820,17 +1817,12 @@ class CableFilterSet(TenancyFilterSet, NetBoxModelFilterSet):
|
||||
# Filter by termination id and cable_end type
|
||||
return self.filter_by_cable_end(queryset, name, value, CableEndChoices.SIDE_B)
|
||||
|
||||
def _has_a_terminations(self, queryset, name, value):
|
||||
def _unterminated(self, queryset, name, value):
|
||||
if value:
|
||||
return queryset.filter(terminations__cable_end=CableEndChoices.SIDE_A)
|
||||
terminated_ids = queryset.filter(terminations__cable_end=CableEndChoices.SIDE_A).filter(terminations__cable_end=CableEndChoices.SIDE_B).values("id")
|
||||
return queryset.exclude(id__in=terminated_ids)
|
||||
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)
|
||||
return queryset.filter(terminations__cable_end=CableEndChoices.SIDE_A).filter(terminations__cable_end=CableEndChoices.SIDE_B)
|
||||
|
||||
|
||||
class CableTerminationFilterSet(BaseFilterSet):
|
||||
|
@ -908,7 +908,7 @@ class VirtualChassisFilterForm(TenancyFilterForm, NetBoxModelFilterSetForm):
|
||||
class CableFilterForm(TenancyFilterForm, NetBoxModelFilterSetForm):
|
||||
model = Cable
|
||||
fieldsets = (
|
||||
(None, ('q', 'filter_id', 'has_a_terminations', 'has_b_terminations', 'tag')),
|
||||
(None, ('q', 'filter_id', 'unterminated', 'tag')),
|
||||
(_('Location'), ('site_id', 'location_id', 'rack_id', 'device_id')),
|
||||
(_('Attributes'), ('type', 'status', 'color', 'length', 'length_unit')),
|
||||
(_('Tenant'), ('tenant_group_id', 'tenant_id')),
|
||||
@ -979,15 +979,8 @@ class CableFilterForm(TenancyFilterForm, NetBoxModelFilterSetForm):
|
||||
choices=add_blank_choice(CableLengthUnitChoices),
|
||||
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'),
|
||||
unterminated = forms.NullBooleanField(
|
||||
label=_('Unterminated'),
|
||||
required=False,
|
||||
widget=forms.Select(
|
||||
choices=BOOLEAN_WITH_BLANK_CHOICES
|
||||
|
Loading…
Reference in New Issue
Block a user