Skip to content

Commit 2b3b951

Browse files
committed
#9073: Fix form behavior when disassociating a ConfigContext from a DataFile
1 parent 08bdb54 commit 2b3b951

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

netbox/extras/forms/model_forms.py

+8
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,14 @@ class Meta:
267267
'tenants', 'tags', 'data_source', 'data_file',
268268
)
269269

270+
def __init__(self, *args, **kwargs):
271+
super().__init__(*args, **kwargs)
272+
273+
# Disable data field when a DataFile has been set
274+
if self.instance.data_file:
275+
self.fields['data'].widget.attrs['readonly'] = True
276+
self.fields['data'].help_text = _('Data is populated from the remote source selected below.')
277+
270278
def clean(self):
271279
super().clean()
272280

netbox/netbox/models/features.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -372,16 +372,15 @@ def is_synced(self):
372372
return self.data_file and self.data_synced >= self.data_file.last_updated
373373

374374
def clean(self):
375-
if self.data_file:
376-
self.sync_data()
377-
self.data_path = self.data_file.path
378375

379-
if self.data_source and not self.data_file:
380-
raise ValidationError({
381-
'data_file': _(f"Must specify a data file when designating a data source.")
382-
})
383-
if self.data_file and not self.data_source:
376+
if self.data_file:
384377
self.data_source = self.data_file.source
378+
self.data_path = self.data_file.path
379+
self.sync_data()
380+
else:
381+
self.data_source = None
382+
self.data_path = ''
383+
self.data_synced = None
385384

386385
super().clean()
387386

0 commit comments

Comments
 (0)