|
@@ -5,6 +5,7 @@ from django.utils.translation import gettext as _
|
|
|
|
|
|
|
|
from dcim.models import DeviceRole, DeviceType, Location, Platform, Region, Site, SiteGroup
|
|
from dcim.models import DeviceRole, DeviceType, Location, Platform, Region, Site, SiteGroup
|
|
|
from extras.choices import *
|
|
from extras.choices import *
|
|
|
|
|
+from extras.forms.mixins import SyncedDataMixin
|
|
|
from extras.models import *
|
|
from extras.models import *
|
|
|
from extras.utils import FeatureQuery
|
|
from extras.utils import FeatureQuery
|
|
|
from netbox.forms import NetBoxModelForm
|
|
from netbox.forms import NetBoxModelForm
|
|
@@ -183,7 +184,7 @@ class TagForm(BootstrapMixin, forms.ModelForm):
|
|
|
]
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
-class ConfigContextForm(BootstrapMixin, forms.ModelForm):
|
|
|
|
|
|
|
+class ConfigContextForm(BootstrapMixin, SyncedDataMixin, forms.ModelForm):
|
|
|
regions = DynamicModelMultipleChoiceField(
|
|
regions = DynamicModelMultipleChoiceField(
|
|
|
queryset=Region.objects.all(),
|
|
queryset=Region.objects.all(),
|
|
|
required=False
|
|
required=False
|
|
@@ -236,10 +237,13 @@ class ConfigContextForm(BootstrapMixin, forms.ModelForm):
|
|
|
queryset=Tag.objects.all(),
|
|
queryset=Tag.objects.all(),
|
|
|
required=False
|
|
required=False
|
|
|
)
|
|
)
|
|
|
- data = JSONField()
|
|
|
|
|
|
|
+ data = JSONField(
|
|
|
|
|
+ required=False
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
fieldsets = (
|
|
fieldsets = (
|
|
|
('Config Context', ('name', 'weight', 'description', 'data', 'is_active')),
|
|
('Config Context', ('name', 'weight', 'description', 'data', 'is_active')),
|
|
|
|
|
+ ('Data Source', ('data_source', 'data_file')),
|
|
|
('Assignment', (
|
|
('Assignment', (
|
|
|
'regions', 'site_groups', 'sites', 'locations', 'device_types', 'roles', 'platforms', 'cluster_types',
|
|
'regions', 'site_groups', 'sites', 'locations', 'device_types', 'roles', 'platforms', 'cluster_types',
|
|
|
'cluster_groups', 'clusters', 'tenant_groups', 'tenants', 'tags',
|
|
'cluster_groups', 'clusters', 'tenant_groups', 'tenants', 'tags',
|
|
@@ -251,9 +255,17 @@ class ConfigContextForm(BootstrapMixin, forms.ModelForm):
|
|
|
fields = (
|
|
fields = (
|
|
|
'name', 'weight', 'description', 'data', 'is_active', 'regions', 'site_groups', 'sites', 'locations',
|
|
'name', 'weight', 'description', 'data', 'is_active', 'regions', 'site_groups', 'sites', 'locations',
|
|
|
'roles', 'device_types', 'platforms', 'cluster_types', 'cluster_groups', 'clusters', 'tenant_groups',
|
|
'roles', 'device_types', 'platforms', 'cluster_types', 'cluster_groups', 'clusters', 'tenant_groups',
|
|
|
- 'tenants', 'tags',
|
|
|
|
|
|
|
+ 'tenants', 'tags', 'data_source', 'data_file',
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+ def clean(self):
|
|
|
|
|
+ super().clean()
|
|
|
|
|
+
|
|
|
|
|
+ if not self.cleaned_data.get('data') and not self.cleaned_data.get('data_source'):
|
|
|
|
|
+ raise forms.ValidationError("Must specify either local data or a data source")
|
|
|
|
|
+
|
|
|
|
|
+ return self.cleaned_data
|
|
|
|
|
+
|
|
|
|
|
|
|
|
class ImageAttachmentForm(BootstrapMixin, forms.ModelForm):
|
|
class ImageAttachmentForm(BootstrapMixin, forms.ModelForm):
|
|
|
|
|
|