Просмотр исходного кода

Merge pull request #3867 from hSaria/3668-address-assign-dns-filter

Fixes #3668: use `q` to search when assigning IP
Jeremy Stretch 6 лет назад
Родитель
Сommit
fc1245c49d

+ 2 - 0
docs/release-notes/version-2.6.md

@@ -6,11 +6,13 @@
 * [#2050](https://github.com/netbox-community/netbox/issues/2050) - Preview image attachments when hovering the link
 * [#2113](https://github.com/netbox-community/netbox/issues/2113) - Allow NAPALM driver settings to be changed with request headers
 * [#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
 * [#3393](https://github.com/netbox-community/netbox/issues/3393) - Paginate the circuits at the provider details view
 * [#3440](https://github.com/netbox-community/netbox/issues/3440) - Add total length to cable trace
 * [#3623](https://github.com/netbox-community/netbox/issues/3623) - Add word expansion during interface creation
+* [#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
 
 ## Bug Fixes

+ 4 - 3
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,8 +942,9 @@ class IPAddressAssignForm(BootstrapMixin, forms.Form):
             api_url="/api/ipam/vrfs/"
         )
     )
-    address = forms.CharField(
-        label='IP Address'
+    q = forms.CharField(
+        required=False,
+        label='Search',
     )
 
 

+ 1 - 1
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
 
 

+ 5 - 6
netbox/ipam/views.py

@@ -756,13 +756,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'],
-            )[: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,

+ 2 - 2
netbox/templates/ipam/ipaddress_assign.html

@@ -24,8 +24,8 @@
             <div class="panel panel-default">
                 <div class="panel-heading"><strong>Select IP Address</strong></div>
                 <div class="panel-body">
-                    {% render_field form.vrf %}
-                    {% render_field form.address %}
+                    {% render_field form.vrf_id %}
+                    {% render_field form.q %}
                 </div>
             </div>
             </div>