mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 20:12:00 -06:00
#6732 - Revert some changes to legacy ASN field on site model
* Re-instates ASN field on Site model * Re-instates ASN field on Site view * Re-instates ASN field on edit form and API, except for where forms instances are new (add site) or instance does not have any existing AS data * Does not re-instate asn field on SiteBulkEditForm * Does not re-instate ASN field on SiteTable * Does not re-instate filter for filterset, but does allow filtering by query (q=34342) * Does not include tests for ASN field on Site model due to planned deprecation
This commit is contained in:
parent
3185cd0b1f
commit
8235b339ee
@ -123,7 +123,7 @@ class SiteSerializer(PrimaryModelSerializer):
|
||||
class Meta:
|
||||
model = Site
|
||||
fields = [
|
||||
'id', 'url', 'display', 'name', 'slug', 'status', 'region', 'group', 'tenant', 'facility', 'asns',
|
||||
'id', 'url', 'display', 'name', 'slug', 'status', 'region', 'group', 'tenant', 'facility', 'asn', 'asns',
|
||||
'time_zone', 'description', 'physical_address', 'shipping_address', 'latitude', 'longitude', 'contact_name',
|
||||
'contact_phone', 'contact_email', 'comments', 'tags', 'custom_fields', 'created', 'last_updated',
|
||||
'asn_count', 'circuit_count', 'device_count', 'prefix_count', 'rack_count', 'virtualmachine_count',
|
||||
|
@ -163,6 +163,7 @@ class SiteFilterSet(PrimaryModelFilterSet, TenancyFilterSet):
|
||||
Q(comments__icontains=value)
|
||||
)
|
||||
try:
|
||||
qs_filter |= Q(asn=int(value.strip()))
|
||||
qs_filter |= Q(asns=int(value.strip()))
|
||||
except ValueError:
|
||||
pass
|
||||
|
@ -122,13 +122,14 @@ class SiteForm(BootstrapMixin, TenancyForm, CustomFieldModelForm):
|
||||
class Meta:
|
||||
model = Site
|
||||
fields = [
|
||||
'name', 'slug', 'status', 'region', 'group', 'tenant_group', 'tenant', 'facility', 'asns', 'time_zone',
|
||||
'description', 'physical_address', 'shipping_address', 'latitude', 'longitude', 'contact_name',
|
||||
'name', 'slug', 'status', 'region', 'group', 'tenant_group', 'tenant', 'facility', 'asn', 'asns',
|
||||
'time_zone', 'description', 'physical_address', 'shipping_address', 'latitude', 'longitude', 'contact_name',
|
||||
'contact_phone', 'contact_email', 'comments', 'tags',
|
||||
]
|
||||
fieldsets = (
|
||||
('Site', (
|
||||
'name', 'slug', 'status', 'region', 'group', 'facility', 'asns', 'time_zone', 'description', 'tags',
|
||||
'name', 'slug', 'status', 'region', 'group', 'facility', 'asn', 'asns', 'time_zone', 'description',
|
||||
'tags',
|
||||
)),
|
||||
('Tenancy', ('tenant_group', 'tenant')),
|
||||
('Contact Info', (
|
||||
@ -152,6 +153,7 @@ class SiteForm(BootstrapMixin, TenancyForm, CustomFieldModelForm):
|
||||
}
|
||||
help_texts = {
|
||||
'name': "Full name of the site",
|
||||
'asn': "BGP autonomous system number. This field is depreciated in favour of the many-to-many field for ASNs",
|
||||
'facility': "Data center provider and facility (e.g. Equinix NY7)",
|
||||
'time_zone': "Local time zone",
|
||||
'description': "Short description (will appear in sites list)",
|
||||
@ -161,6 +163,18 @@ class SiteForm(BootstrapMixin, TenancyForm, CustomFieldModelForm):
|
||||
'longitude': "Longitude in decimal format (xx.yyyyyy)"
|
||||
}
|
||||
|
||||
def __init__(self, instance, *args, **kwargs):
|
||||
super(SiteForm, self).__init__(instance=instance, *args, **kwargs)
|
||||
if instance is None or (instance and (instance.asn is None or instance.asn == '')):
|
||||
site_fieldset = list(self.Meta.fieldsets[0][1])
|
||||
site_fieldset.pop(6)
|
||||
self.Meta.fieldsets = (
|
||||
('Site', tuple(site_fieldset)),
|
||||
self.Meta.fieldsets[1],
|
||||
self.Meta.fieldsets[2],
|
||||
)
|
||||
del self.fields['asn']
|
||||
|
||||
|
||||
class LocationForm(BootstrapMixin, TenancyForm, CustomFieldModelForm):
|
||||
region = DynamicModelChoiceField(
|
||||
|
@ -1,18 +0,0 @@
|
||||
# Generated by Django 3.2.8 on 2021-10-25 04:33
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('dcim', '0137_relax_uniqueness_constraints'),
|
||||
('ipam', '0051_asn_model')
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='site',
|
||||
name='asn',
|
||||
),
|
||||
]
|
@ -189,6 +189,12 @@ class Site(PrimaryModel):
|
||||
blank=True,
|
||||
help_text='Local facility ID or description'
|
||||
)
|
||||
asn = ASNField(
|
||||
blank=True,
|
||||
null=True,
|
||||
verbose_name='ASN',
|
||||
help_text='32-bit autonomous system number'
|
||||
)
|
||||
time_zone = TimeZoneField(
|
||||
blank=True
|
||||
)
|
||||
@ -251,7 +257,7 @@ class Site(PrimaryModel):
|
||||
objects = RestrictedQuerySet.as_manager()
|
||||
|
||||
clone_fields = [
|
||||
'status', 'region', 'group', 'tenant', 'facility', 'time_zone', 'description', 'physical_address',
|
||||
'status', 'region', 'group', 'tenant', 'facility', 'asn', 'time_zone', 'description', 'physical_address',
|
||||
'shipping_address', 'latitude', 'longitude', 'contact_name', 'contact_phone', 'contact_email',
|
||||
]
|
||||
|
||||
|
@ -80,6 +80,10 @@
|
||||
<th scope="row">Description</th>
|
||||
<td>{{ object.description|placeholder }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">AS Number</th>
|
||||
<td>{{ object.asn|placeholder }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Time Zone</th>
|
||||
<td>
|
||||
|
Loading…
Reference in New Issue
Block a user