Skip to content

Commit

Permalink
Closes #2701: Enable filtering of prefixes by exact prefix value
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Dec 19, 2018
1 parent 82e8c01 commit 68cb8b6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
v2.5.2 (FUTURE)

## Enhancements

* [#2701](https://github.com/digitalocean/netbox/issues/2701) - Enable filtering of prefixes by exact prefix value

## Bug Fixes

* [#2707](https://github.com/digitalocean/netbox/issues/2707) - Correct permission evaluation for circuit termination cabling
Expand Down
13 changes: 13 additions & 0 deletions netbox/ipam/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ class PrefixFilter(CustomFieldFilterSet, django_filters.FilterSet):
method='search',
label='Search',
)
prefix = django_filters.CharFilter(
method='filter_prefix',
label='Prefix',
)
within = django_filters.CharFilter(
method='search_within',
label='Within prefix',
Expand Down Expand Up @@ -197,6 +201,15 @@ def search(self, queryset, name, value):
pass
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):
value = value.strip()
if not value:
Expand Down

0 comments on commit 68cb8b6

Please sign in to comment.