1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Closes #1684: Replaced prefix 'parent' filter with 'within' and 'within_include'

This commit is contained in:
Jeremy Stretch
2017-11-02 13:15:25 -04:00
parent b8df05cf88
commit 626fbd1d10
2 changed files with 23 additions and 4 deletions

View File

@ -102,9 +102,18 @@ class PrefixFilter(CustomFieldFilterSet, django_filters.FilterSet):
method='search',
label='Search',
)
# TODO: Deprecate in v2.3.0
parent = django_filters.CharFilter(
method='search_by_parent',
label='Parent prefix',
method='search_within_include',
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(
method='filter_mask_length',
@ -177,7 +186,17 @@ class PrefixFilter(CustomFieldFilterSet, django_filters.FilterSet):
pass
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()
if not value:
return queryset

View File

@ -362,7 +362,7 @@ def prefix_status_choices():
class PrefixFilterForm(BootstrapMixin, CustomFieldFilterForm):
model = Prefix
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',
}))
family = forms.ChoiceField(required=False, choices=IP_FAMILY_CHOICES, label='Address family')