mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-14 01:41:22 -06:00
Closes #2701: Enable filtering of prefixes by exact prefix value
This commit is contained in:
parent
82e8c0152e
commit
68cb8b6895
@ -1,5 +1,9 @@
|
|||||||
v2.5.2 (FUTURE)
|
v2.5.2 (FUTURE)
|
||||||
|
|
||||||
|
## Enhancements
|
||||||
|
|
||||||
|
* [#2701](https://github.com/digitalocean/netbox/issues/2701) - Enable filtering of prefixes by exact prefix value
|
||||||
|
|
||||||
## Bug Fixes
|
## Bug Fixes
|
||||||
|
|
||||||
* [#2707](https://github.com/digitalocean/netbox/issues/2707) - Correct permission evaluation for circuit termination cabling
|
* [#2707](https://github.com/digitalocean/netbox/issues/2707) - Correct permission evaluation for circuit termination cabling
|
||||||
|
@ -112,6 +112,10 @@ class PrefixFilter(CustomFieldFilterSet, django_filters.FilterSet):
|
|||||||
method='search',
|
method='search',
|
||||||
label='Search',
|
label='Search',
|
||||||
)
|
)
|
||||||
|
prefix = django_filters.CharFilter(
|
||||||
|
method='filter_prefix',
|
||||||
|
label='Prefix',
|
||||||
|
)
|
||||||
within = django_filters.CharFilter(
|
within = django_filters.CharFilter(
|
||||||
method='search_within',
|
method='search_within',
|
||||||
label='Within prefix',
|
label='Within prefix',
|
||||||
@ -197,6 +201,15 @@ class PrefixFilter(CustomFieldFilterSet, django_filters.FilterSet):
|
|||||||
pass
|
pass
|
||||||
return queryset.filter(qs_filter)
|
return queryset.filter(qs_filter)
|
||||||
|
|
||||||
|
def filter_prefix(self, queryset, name, value):
|
||||||
|
if not value.strip():
|
||||||
|
return queryset
|
||||||
|
try:
|
||||||
|
query = str(netaddr.IPNetwork(value).cidr)
|
||||||
|
return queryset.filter(prefix=query)
|
||||||
|
except ValidationError:
|
||||||
|
return queryset.none()
|
||||||
|
|
||||||
def search_within(self, queryset, name, value):
|
def search_within(self, queryset, name, value):
|
||||||
value = value.strip()
|
value = value.strip()
|
||||||
if not value:
|
if not value:
|
||||||
|
Loading…
Reference in New Issue
Block a user