diff --git a/netbox/extras/forms/filtersets.py b/netbox/extras/forms/filtersets.py index 2f1460688..675315bed 100644 --- a/netbox/extras/forms/filtersets.py +++ b/netbox/extras/forms/filtersets.py @@ -359,6 +359,20 @@ class ConfigContextProfileFilterForm(SavedFiltersMixin, FilterForm): model = ConfigContextProfile fieldsets = ( FieldSet('q', 'filter_id'), + FieldSet('data_source_id', 'data_file_id', name=_('Data')), + ) + data_source_id = DynamicModelMultipleChoiceField( + queryset=DataSource.objects.all(), + required=False, + label=_('Data source') + ) + data_file_id = DynamicModelMultipleChoiceField( + queryset=DataFile.objects.all(), + required=False, + label=_('Data file'), + query_params={ + 'source_id': '$data_source_id' + } ) diff --git a/netbox/extras/forms/model_forms.py b/netbox/extras/forms/model_forms.py index 162d0502d..37ee10604 100644 --- a/netbox/extras/forms/model_forms.py +++ b/netbox/extras/forms/model_forms.py @@ -586,7 +586,7 @@ class TagForm(ChangelogMessageMixin, forms.ModelForm): ] -class ConfigContextProfileForm(NetBoxModelForm): +class ConfigContextProfileForm(SyncedDataMixin, NetBoxModelForm): schema = JSONField( label=_('Schema'), required=False, @@ -606,7 +606,7 @@ class ConfigContextProfileForm(NetBoxModelForm): class Meta: model = ConfigContextProfile fields = ( - 'name', 'description', 'schema', 'data_source', 'data_file', 'comments', 'tags', + 'name', 'description', 'schema', 'data_source', 'data_file', 'auto_sync_enabled', 'comments', 'tags', ) diff --git a/netbox/extras/models/configs.py b/netbox/extras/models/configs.py index e4a242af5..a9d233568 100644 --- a/netbox/extras/models/configs.py +++ b/netbox/extras/models/configs.py @@ -60,6 +60,13 @@ class ConfigContextProfile(SyncedDataMixin, PrimaryModel): def __str__(self): return self.name + def sync_data(self): + """ + Synchronize schema from the designated DataFile (if any). + """ + self.schema = self.data_file.get_data() + sync_data.alters_data = True + class ConfigContext(SyncedDataMixin, CloningMixin, CustomLinksMixin, ChangeLoggedModel): """ diff --git a/netbox/extras/tables/tables.py b/netbox/extras/tables/tables.py index 10f6e0344..2a8d89a5c 100644 --- a/netbox/extras/tables/tables.py +++ b/netbox/extras/tables/tables.py @@ -552,6 +552,18 @@ class ConfigContextProfileTable(NetBoxTable): verbose_name=_('Name'), linkify=True ) + data_source = tables.Column( + verbose_name=_('Data Source'), + linkify=True + ) + data_file = tables.Column( + verbose_name=_('Data File'), + linkify=True + ) + is_synced = columns.BooleanColumn( + orderable=False, + verbose_name=_('Synced') + ) tags = columns.TagColumn( url_name='extras:configcontextprofile_list' ) @@ -559,9 +571,10 @@ class ConfigContextProfileTable(NetBoxTable): class Meta(NetBoxTable.Meta): model = ConfigContextProfile fields = ( - 'pk', 'id', 'name', 'description', 'comments', 'tags', 'created', 'last_updated', + 'pk', 'id', 'name', 'description', 'comments', 'data_source', 'data_file', 'is_synced', 'tags', 'created', + 'last_updated', ) - default_columns = ('pk', 'name', 'description') + default_columns = ('pk', 'name', 'is_synced', 'description') class ConfigContextTable(NetBoxTable):