Skip to content

Commit

Permalink
#9073: Fix form behavior when disassociating a ConfigContext from a D…
Browse files Browse the repository at this point in the history
…ataFile
  • Loading branch information
jeremystretch committed Mar 20, 2023
1 parent 08bdb54 commit 2b3b951
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
8 changes: 8 additions & 0 deletions netbox/extras/forms/model_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,14 @@ class Meta:
'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()

Expand Down
15 changes: 7 additions & 8 deletions netbox/netbox/models/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,16 +372,15 @@ def is_synced(self):
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()

Expand Down

0 comments on commit 2b3b951

Please sign in to comment.