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
|
import django_filters
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
|
from django.db.models import Q
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
from extras.filtersets import LocalConfigContextFilterSet
|
from extras.filtersets import LocalConfigContextFilterSet
|
||||||
@ -1745,13 +1746,9 @@ 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(
|
unterminated = django_filters.BooleanFilter(
|
||||||
method='_has_a_terminations',
|
method='_unterminated',
|
||||||
label=_('Has a terminations'),
|
label=_('Unterminated'),
|
||||||
)
|
|
||||||
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
|
||||||
@ -1820,17 +1817,12 @@ 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):
|
def _unterminated(self, queryset, name, value):
|
||||||
if 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:
|
else:
|
||||||
return queryset.exclude(terminations__cable_end=CableEndChoices.SIDE_A)
|
return queryset.filter(terminations__cable_end=CableEndChoices.SIDE_A).filter(terminations__cable_end=CableEndChoices.SIDE_B)
|
||||||
|
|
||||||
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):
|
||||||
|
@ -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', 'has_a_terminations', 'has_b_terminations', 'tag')),
|
(None, ('q', 'filter_id', 'unterminated', '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,15 +979,8 @@ class CableFilterForm(TenancyFilterForm, NetBoxModelFilterSetForm):
|
|||||||
choices=add_blank_choice(CableLengthUnitChoices),
|
choices=add_blank_choice(CableLengthUnitChoices),
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
has_a_terminations = forms.NullBooleanField(
|
unterminated = forms.NullBooleanField(
|
||||||
label=_('Has a terminations'),
|
label=_('Unterminated'),
|
||||||
required=False,
|
|
||||||
widget=forms.Select(
|
|
||||||
choices=BOOLEAN_WITH_BLANK_CHOICES
|
|
||||||
)
|
|
||||||
)
|
|
||||||
has_b_terminations = forms.NullBooleanField(
|
|
||||||
label=_('Has b terminations'),
|
|
||||||
required=False,
|
required=False,
|
||||||
widget=forms.Select(
|
widget=forms.Select(
|
||||||
choices=BOOLEAN_WITH_BLANK_CHOICES
|
choices=BOOLEAN_WITH_BLANK_CHOICES
|
||||||
|
Loading…
Reference in New Issue
Block a user