From 1cdbfd6d60ab5cefb6cd3f8497fb3f565618b117 Mon Sep 17 00:00:00 2001 From: Saria Hajjar Date: Thu, 9 Jan 2020 10:00:02 +0000 Subject: [PATCH 1/4] Fixes #3668: search address by DNS name when assigning --- docs/release-notes/version-2.6.md | 1 + netbox/ipam/forms.py | 7 ++++++- netbox/ipam/tables.py | 2 +- netbox/ipam/views.py | 1 + netbox/templates/ipam/ipaddress_assign.html | 1 + 5 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/release-notes/version-2.6.md b/docs/release-notes/version-2.6.md index f3ff8798a..341e62a79 100644 --- a/docs/release-notes/version-2.6.md +++ b/docs/release-notes/version-2.6.md @@ -4,6 +4,7 @@ * [#2050](https://github.com/netbox-community/netbox/issues/2050) - Preview image attachments when hovering the link * [#3187](https://github.com/netbox-community/netbox/issues/3187) - Add rack selection field to rack elevations +* [#3668](https://github.com/netbox-community/netbox/issues/3668) - Search by DNS name when assigning IP address ## Bug Fixes diff --git a/netbox/ipam/forms.py b/netbox/ipam/forms.py index 413e72eaf..f4bcfb2e6 100644 --- a/netbox/ipam/forms.py +++ b/netbox/ipam/forms.py @@ -943,7 +943,12 @@ class IPAddressAssignForm(BootstrapMixin, forms.Form): ) ) address = forms.CharField( - label='IP Address' + label='IP Address', + required=False, + ) + dns_name = forms.CharField( + label='DNS Name', + required=False, ) diff --git a/netbox/ipam/tables.py b/netbox/ipam/tables.py index e4d2bf8b4..d6e26f6a1 100644 --- a/netbox/ipam/tables.py +++ b/netbox/ipam/tables.py @@ -373,7 +373,7 @@ class IPAddressAssignTable(BaseTable): class Meta(BaseTable.Meta): model = IPAddress - fields = ('address', 'vrf', 'status', 'role', 'tenant', 'parent', 'interface', 'description') + fields = ('address', 'dns_name', 'vrf', 'status', 'role', 'tenant', 'parent', 'interface', 'description') orderable = False diff --git a/netbox/ipam/views.py b/netbox/ipam/views.py index 2cc1a0ea8..d38366d54 100644 --- a/netbox/ipam/views.py +++ b/netbox/ipam/views.py @@ -745,6 +745,7 @@ class IPAddressAssignView(PermissionRequiredMixin, View): ).filter( vrf=form.cleaned_data['vrf'], address__istartswith=form.cleaned_data['address'], + dns_name__icontains=form.cleaned_data['dns_name'], )[:100] # Limit to 100 results table = tables.IPAddressAssignTable(queryset) diff --git a/netbox/templates/ipam/ipaddress_assign.html b/netbox/templates/ipam/ipaddress_assign.html index 579f2d98b..349c06919 100644 --- a/netbox/templates/ipam/ipaddress_assign.html +++ b/netbox/templates/ipam/ipaddress_assign.html @@ -26,6 +26,7 @@
{% render_field form.vrf %} {% render_field form.address %} + {% render_field form.dns_name %}
From 472486acd60e1e4c37bbba24eb3e967c95d690c0 Mon Sep 17 00:00:00 2001 From: Saria Hajjar Date: Thu, 9 Jan 2020 16:26:11 +0000 Subject: [PATCH 2/4] Changed to `q` filter --- netbox/ipam/forms.py | 10 +++------- netbox/ipam/views.py | 12 +++++------- netbox/templates/ipam/ipaddress_assign.html | 5 ++--- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/netbox/ipam/forms.py b/netbox/ipam/forms.py index f4bcfb2e6..c3387a5aa 100644 --- a/netbox/ipam/forms.py +++ b/netbox/ipam/forms.py @@ -933,7 +933,7 @@ class IPAddressBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEd class IPAddressAssignForm(BootstrapMixin, forms.Form): - vrf = forms.ModelChoiceField( + vrf_id = forms.ModelChoiceField( queryset=VRF.objects.all(), required=False, label='VRF', @@ -942,13 +942,9 @@ class IPAddressAssignForm(BootstrapMixin, forms.Form): api_url="/api/ipam/vrfs/" ) ) - address = forms.CharField( - label='IP Address', - required=False, - ) - dns_name = forms.CharField( - label='DNS Name', + q = forms.CharField( required=False, + label='Search', ) diff --git a/netbox/ipam/views.py b/netbox/ipam/views.py index d6cada398..084cf1205 100644 --- a/netbox/ipam/views.py +++ b/netbox/ipam/views.py @@ -749,14 +749,12 @@ class IPAddressAssignView(PermissionRequiredMixin, View): if form.is_valid(): - queryset = IPAddress.objects.prefetch_related( + addresses = IPAddress.objects.prefetch_related( 'vrf', 'tenant', 'interface__device', 'interface__virtual_machine' - ).filter( - vrf=form.cleaned_data['vrf'], - address__istartswith=form.cleaned_data['address'], - dns_name__icontains=form.cleaned_data['dns_name'], - )[:100] # Limit to 100 results - table = tables.IPAddressAssignTable(queryset) + ) + # Limit to 100 results + addresses = filters.IPAddressFilter(request.POST, addresses).qs[:100] + table = tables.IPAddressAssignTable(addresses) return render(request, 'ipam/ipaddress_assign.html', { 'form': form, diff --git a/netbox/templates/ipam/ipaddress_assign.html b/netbox/templates/ipam/ipaddress_assign.html index 349c06919..ab163533f 100644 --- a/netbox/templates/ipam/ipaddress_assign.html +++ b/netbox/templates/ipam/ipaddress_assign.html @@ -24,9 +24,8 @@
Select IP Address
- {% render_field form.vrf %} - {% render_field form.address %} - {% render_field form.dns_name %} + {% render_field form.vrf_id %} + {% render_field form.q %}
From 581ed52b2424a3cc9f5b6dc1fd998591f1754344 Mon Sep 17 00:00:00 2001 From: Saria Hajjar Date: Thu, 9 Jan 2020 16:30:13 +0000 Subject: [PATCH 3/4] Added changelog for 3009 --- docs/release-notes/version-2.6.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/release-notes/version-2.6.md b/docs/release-notes/version-2.6.md index 1f3e9a430..afc9b87c1 100644 --- a/docs/release-notes/version-2.6.md +++ b/docs/release-notes/version-2.6.md @@ -4,6 +4,7 @@ * [#2050](https://github.com/netbox-community/netbox/issues/2050) - Preview image attachments when hovering the link * [#2589](https://github.com/netbox-community/netbox/issues/2589) - Toggle for showing available prefixes/ip addresses +* [#3009](https://github.com/netbox-community/netbox/issues/3009) - Search by description when assigning IP address * [#3187](https://github.com/netbox-community/netbox/issues/3187) - Add rack selection field to rack elevations * [#3668](https://github.com/netbox-community/netbox/issues/3668) - Search by DNS name when assigning IP address * [#3851](https://github.com/netbox-community/netbox/issues/3851) - Allow passing initial data to custom script forms From 86865b91f8e8b1a684ed5fec688d7aed4945d48a Mon Sep 17 00:00:00 2001 From: Saria Hajjar Date: Thu, 9 Jan 2020 16:32:01 +0000 Subject: [PATCH 4/4] Added changelog for 3009 again as I accidentally removed it while merging --- docs/release-notes/version-2.6.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/release-notes/version-2.6.md b/docs/release-notes/version-2.6.md index a6e54cbef..e054e7684 100644 --- a/docs/release-notes/version-2.6.md +++ b/docs/release-notes/version-2.6.md @@ -4,6 +4,7 @@ * [#2050](https://github.com/netbox-community/netbox/issues/2050) - Preview image attachments when hovering the link * [#2589](https://github.com/netbox-community/netbox/issues/2589) - Toggle for showing available prefixes/ip addresses +* [#3009](https://github.com/netbox-community/netbox/issues/3009) - Search by description when assigning IP address * [#3090](https://github.com/netbox-community/netbox/issues/3090) - Add filter field for device interfaces * [#3187](https://github.com/netbox-community/netbox/issues/3187) - Add rack selection field to rack elevations * [#3440](https://github.com/netbox-community/netbox/issues/3440) - Add total length to cable trace