mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 18:08:38 -06:00
#9073: Fix form behavior when disassociating a ConfigContext from a DataFile
This commit is contained in:
parent
08bdb54cb4
commit
2b3b9517d2
@ -267,6 +267,14 @@ class ConfigContextForm(BootstrapMixin, SyncedDataMixin, forms.ModelForm):
|
|||||||
'tenants', 'tags', 'data_source', 'data_file',
|
'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):
|
def clean(self):
|
||||||
super().clean()
|
super().clean()
|
||||||
|
|
||||||
|
@ -372,16 +372,15 @@ class SyncedDataMixin(models.Model):
|
|||||||
return self.data_file and self.data_synced >= self.data_file.last_updated
|
return self.data_file and self.data_synced >= self.data_file.last_updated
|
||||||
|
|
||||||
def clean(self):
|
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:
|
if 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:
|
|
||||||
self.data_source = self.data_file.source
|
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()
|
super().clean()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user