mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 09:28:38 -06:00
Closes #1684: Replaced prefix 'parent' filter with 'within' and 'within_include'
This commit is contained in:
parent
b8df05cf88
commit
626fbd1d10
@ -102,9 +102,18 @@ class PrefixFilter(CustomFieldFilterSet, django_filters.FilterSet):
|
|||||||
method='search',
|
method='search',
|
||||||
label='Search',
|
label='Search',
|
||||||
)
|
)
|
||||||
|
# TODO: Deprecate in v2.3.0
|
||||||
parent = django_filters.CharFilter(
|
parent = django_filters.CharFilter(
|
||||||
method='search_by_parent',
|
method='search_within_include',
|
||||||
label='Parent prefix',
|
label='Parent prefix (deprecated)',
|
||||||
|
)
|
||||||
|
within = django_filters.CharFilter(
|
||||||
|
method='search_within',
|
||||||
|
label='Within prefix',
|
||||||
|
)
|
||||||
|
within_include = django_filters.CharFilter(
|
||||||
|
method='search_within_include',
|
||||||
|
label='Within and including prefix',
|
||||||
)
|
)
|
||||||
mask_length = django_filters.NumberFilter(
|
mask_length = django_filters.NumberFilter(
|
||||||
method='filter_mask_length',
|
method='filter_mask_length',
|
||||||
@ -177,7 +186,17 @@ class PrefixFilter(CustomFieldFilterSet, django_filters.FilterSet):
|
|||||||
pass
|
pass
|
||||||
return queryset.filter(qs_filter)
|
return queryset.filter(qs_filter)
|
||||||
|
|
||||||
def search_by_parent(self, queryset, name, value):
|
def search_within(self, queryset, name, value):
|
||||||
|
value = value.strip()
|
||||||
|
if not value:
|
||||||
|
return queryset
|
||||||
|
try:
|
||||||
|
query = str(IPNetwork(value).cidr)
|
||||||
|
return queryset.filter(prefix__net_contained=query)
|
||||||
|
except (AddrFormatError, ValueError):
|
||||||
|
return queryset.none()
|
||||||
|
|
||||||
|
def search_within_include(self, queryset, name, value):
|
||||||
value = value.strip()
|
value = value.strip()
|
||||||
if not value:
|
if not value:
|
||||||
return queryset
|
return queryset
|
||||||
|
@ -362,7 +362,7 @@ def prefix_status_choices():
|
|||||||
class PrefixFilterForm(BootstrapMixin, CustomFieldFilterForm):
|
class PrefixFilterForm(BootstrapMixin, CustomFieldFilterForm):
|
||||||
model = Prefix
|
model = Prefix
|
||||||
q = forms.CharField(required=False, label='Search')
|
q = forms.CharField(required=False, label='Search')
|
||||||
parent = forms.CharField(required=False, label='Parent prefix', widget=forms.TextInput(attrs={
|
within_include = forms.CharField(required=False, label='Search within', widget=forms.TextInput(attrs={
|
||||||
'placeholder': 'Prefix',
|
'placeholder': 'Prefix',
|
||||||
}))
|
}))
|
||||||
family = forms.ChoiceField(required=False, choices=IP_FAMILY_CHOICES, label='Address family')
|
family = forms.ChoiceField(required=False, choices=IP_FAMILY_CHOICES, label='Address family')
|
||||||
|
Loading…
Reference in New Issue
Block a user