|
@@ -23,7 +23,7 @@ from utilities.forms.fields import (
|
|
|
NumericArrayField,
|
|
NumericArrayField,
|
|
|
SlugField,
|
|
SlugField,
|
|
|
)
|
|
)
|
|
|
-from utilities.forms.rendering import FieldSet, InlineFields, TabbedGroups
|
|
|
|
|
|
|
+from utilities.forms.rendering import FieldSet, InlineFields, M2MAddRemoveFields, TabbedGroups
|
|
|
from utilities.forms.widgets import (
|
|
from utilities.forms.widgets import (
|
|
|
APISelect,
|
|
APISelect,
|
|
|
ClearableFileInput,
|
|
ClearableFileInput,
|
|
@@ -137,9 +137,14 @@ class SiteForm(TenancyForm, PrimaryModelForm):
|
|
|
required=False,
|
|
required=False,
|
|
|
quick_add=True
|
|
quick_add=True
|
|
|
)
|
|
)
|
|
|
- asns = DynamicModelMultipleChoiceField(
|
|
|
|
|
|
|
+ add_asns = DynamicModelMultipleChoiceField(
|
|
|
queryset=ASN.objects.all(),
|
|
queryset=ASN.objects.all(),
|
|
|
- label=_('ASNs'),
|
|
|
|
|
|
|
+ label=_('Add ASNs'),
|
|
|
|
|
+ required=False
|
|
|
|
|
+ )
|
|
|
|
|
+ remove_asns = DynamicModelMultipleChoiceField(
|
|
|
|
|
+ queryset=ASN.objects.all(),
|
|
|
|
|
+ label=_('Remove ASNs'),
|
|
|
required=False
|
|
required=False
|
|
|
)
|
|
)
|
|
|
slug = SlugField()
|
|
slug = SlugField()
|
|
@@ -151,7 +156,8 @@ class SiteForm(TenancyForm, PrimaryModelForm):
|
|
|
|
|
|
|
|
fieldsets = (
|
|
fieldsets = (
|
|
|
FieldSet(
|
|
FieldSet(
|
|
|
- 'name', 'slug', 'status', 'region', 'group', 'facility', 'asns', 'time_zone', 'description', 'tags',
|
|
|
|
|
|
|
+ 'name', 'slug', 'status', 'region', 'group', 'facility', M2MAddRemoveFields('asns'), 'time_zone',
|
|
|
|
|
+ 'description', 'tags',
|
|
|
name=_('Site')
|
|
name=_('Site')
|
|
|
),
|
|
),
|
|
|
FieldSet('tenant_group', 'tenant', name=_('Tenancy')),
|
|
FieldSet('tenant_group', 'tenant', name=_('Tenancy')),
|
|
@@ -161,7 +167,7 @@ class SiteForm(TenancyForm, PrimaryModelForm):
|
|
|
class Meta:
|
|
class Meta:
|
|
|
model = Site
|
|
model = Site
|
|
|
fields = (
|
|
fields = (
|
|
|
- 'name', 'slug', 'status', 'region', 'group', 'tenant_group', 'tenant', 'facility', 'asns', 'time_zone',
|
|
|
|
|
|
|
+ 'name', 'slug', 'status', 'region', 'group', 'tenant_group', 'tenant', 'facility', 'time_zone',
|
|
|
'description', 'physical_address', 'shipping_address', 'latitude', 'longitude', 'owner', 'comments', 'tags',
|
|
'description', 'physical_address', 'shipping_address', 'latitude', 'longitude', 'owner', 'comments', 'tags',
|
|
|
)
|
|
)
|
|
|
widgets = {
|
|
widgets = {
|
|
@@ -177,6 +183,14 @@ class SiteForm(TenancyForm, PrimaryModelForm):
|
|
|
),
|
|
),
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ def __init__(self, *args, **kwargs):
|
|
|
|
|
+ super().__init__(*args, **kwargs)
|
|
|
|
|
+ if self.instance.pk:
|
|
|
|
|
+ self.fields['remove_asns'].widget.add_query_param('site_id', self.instance.pk)
|
|
|
|
|
+ else:
|
|
|
|
|
+ self.fields.pop('remove_asns')
|
|
|
|
|
+ self.fields['add_asns'].label = _('ASNs')
|
|
|
|
|
+
|
|
|
|
|
|
|
|
class LocationForm(TenancyForm, NestedGroupModelForm):
|
|
class LocationForm(TenancyForm, NestedGroupModelForm):
|
|
|
site = DynamicModelChoiceField(
|
|
site = DynamicModelChoiceField(
|