1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

#9073: Fix form behavior when disassociating a ConfigContext from a DataFile

This commit is contained in:
jeremystretch
2023-03-20 15:40:49 -04:00
parent 08bdb54cb4
commit 2b3b9517d2
2 changed files with 15 additions and 8 deletions

View File

@ -267,6 +267,14 @@ class ConfigContextForm(BootstrapMixin, SyncedDataMixin, forms.ModelForm):
'tenants', 'tags', 'data_source', 'data_file',
)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Disable data field when a DataFile has been set
if self.instance.data_file:
self.fields['data'].widget.attrs['readonly'] = True
self.fields['data'].help_text = _('Data is populated from the remote source selected below.')
def clean(self):
super().clean()

View File

@ -372,16 +372,15 @@ class SyncedDataMixin(models.Model):
return self.data_file and self.data_synced >= self.data_file.last_updated
def clean(self):
if self.data_file:
self.sync_data()
self.data_path = self.data_file.path
if self.data_source and not self.data_file:
raise ValidationError({
'data_file': _(f"Must specify a data file when designating a data source.")
})
if self.data_file and not self.data_source:
if self.data_file:
self.data_source = self.data_file.source
self.data_path = self.data_file.path
self.sync_data()
else:
self.data_source = None
self.data_path = ''
self.data_synced = None
super().clean()