From 21468fff25cb87327d77340900fd2ff0c6355caf Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Tue, 18 Jan 2022 15:36:21 -0500 Subject: [PATCH] Closes #8367: Add ASNs to global search function --- docs/release-notes/version-3.1.md | 3 ++- netbox/ipam/filtersets.py | 4 ++++ netbox/ipam/tables/ip.py | 6 ++++-- netbox/netbox/constants.py | 14 +++++++++++--- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/docs/release-notes/version-3.1.md b/docs/release-notes/version-3.1.md index fdb7c18b5..b985a5651 100644 --- a/docs/release-notes/version-3.1.md +++ b/docs/release-notes/version-3.1.md @@ -4,7 +4,8 @@ ### Enhancements -* [#8275](https://github.com/netbox-community/netbox/issues/8275) - Change ASN display column from ASDOT to ASPLAIN. Add ASDOT display column. +* [#8275](https://github.com/netbox-community/netbox/issues/8275) - Introduce alternative ASDOT-formatted column for ASNs +* [#8367](https://github.com/netbox-community/netbox/issues/8367) - Add ASNs to global search function ### Bug Fixes diff --git a/netbox/ipam/filtersets.py b/netbox/ipam/filtersets.py index df6ee1055..d7e1ee47e 100644 --- a/netbox/ipam/filtersets.py +++ b/netbox/ipam/filtersets.py @@ -209,6 +209,10 @@ class ASNFilterSet(OrganizationalModelFilterSet, TenancyFilterSet): if not value.strip(): return queryset qs_filter = Q(description__icontains=value) + try: + qs_filter |= Q(asn=int(value)) + except ValueError: + pass return queryset.filter(qs_filter) diff --git a/netbox/ipam/tables/ip.py b/netbox/ipam/tables/ip.py index eca35de1a..49892f557 100644 --- a/netbox/ipam/tables/ip.py +++ b/netbox/ipam/tables/ip.py @@ -114,7 +114,6 @@ class ASNTable(BaseTable): linkify=True, verbose_name='ASDOT' ) - site_count = LinkedCountColumn( viewname='dcim:site_list', url_params={'asn_id': 'pk'}, @@ -124,7 +123,10 @@ class ASNTable(BaseTable): class Meta(BaseTable.Meta): model = ASN - fields = ('pk', 'asn', 'asn_asdot', 'rir', 'site_count', 'tenant', 'description', 'actions', 'created', 'last_updated',) + fields = ( + 'pk', 'asn', 'asn_asdot', 'rir', 'site_count', 'tenant', 'description', 'actions', 'created', + 'last_updated', + ) default_columns = ('pk', 'asn', 'rir', 'site_count', 'sites', 'tenant', 'actions') diff --git a/netbox/netbox/constants.py b/netbox/netbox/constants.py index 3e935e722..e087423bb 100644 --- a/netbox/netbox/constants.py +++ b/netbox/netbox/constants.py @@ -12,9 +12,11 @@ from dcim.tables import ( CableTable, DeviceTable, DeviceTypeTable, PowerFeedTable, RackTable, RackReservationTable, LocationTable, SiteTable, VirtualChassisTable, ) -from ipam.filtersets import AggregateFilterSet, IPAddressFilterSet, PrefixFilterSet, VLANFilterSet, VRFFilterSet -from ipam.models import Aggregate, IPAddress, Prefix, VLAN, VRF -from ipam.tables import AggregateTable, IPAddressTable, PrefixTable, VLANTable, VRFTable +from ipam.filtersets import ( + AggregateFilterSet, ASNFilterSet, IPAddressFilterSet, PrefixFilterSet, VLANFilterSet, VRFFilterSet, +) +from ipam.models import Aggregate, ASN, IPAddress, Prefix, VLAN, VRF +from ipam.tables import AggregateTable, ASNTable, IPAddressTable, PrefixTable, VLANTable, VRFTable from tenancy.filtersets import TenantFilterSet from tenancy.models import Tenant from tenancy.tables import TenantTable @@ -170,6 +172,12 @@ SEARCH_TYPES = OrderedDict(( 'table': VLANTable, 'url': 'ipam:vlan_list', }), + ('asn', { + 'queryset': ASN.objects.prefetch_related('rir', 'tenant'), + 'filterset': ASNFilterSet, + 'table': ASNTable, + 'url': 'ipam:asn_list', + }), # Tenancy ('tenant', { 'queryset': Tenant.objects.prefetch_related('group'),