diff --git a/netbox/core/api/serializers.py b/netbox/core/api/serializers.py index 33665e273..b168e2ef1 100644 --- a/netbox/core/api/serializers.py +++ b/netbox/core/api/serializers.py @@ -31,7 +31,7 @@ class DataSourceSerializer(NetBoxModelSerializer): class Meta: model = DataSource fields = [ - 'id', 'url', 'display', 'name', 'type', 'url', 'enabled', 'status', 'description', 'parameters', + 'id', 'url', 'display', 'name', 'type', 'url', 'enabled', 'status', 'description', 'comments', 'parameters', 'ignore_rules', 'created', 'last_updated', 'file_count', ] diff --git a/netbox/core/filtersets.py b/netbox/core/filtersets.py index d05b2e61a..ce5fc68ef 100644 --- a/netbox/core/filtersets.py +++ b/netbox/core/filtersets.py @@ -3,7 +3,7 @@ from django.utils.translation import gettext as _ import django_filters -from netbox.filtersets import ChangeLoggedModelFilterSet +from netbox.filtersets import NetBoxModelFilterSet from .models import * __all__ = ( @@ -12,7 +12,7 @@ __all__ = ( ) -class DataSourceFilterSet(ChangeLoggedModelFilterSet): +class DataSourceFilterSet(NetBoxModelFilterSet): class Meta: model = DataSource @@ -23,7 +23,8 @@ class DataSourceFilterSet(ChangeLoggedModelFilterSet): return queryset return queryset.filter( Q(name__icontains=value) | - Q(description__icontains=value) + Q(description__icontains=value) | + Q(comments__icontains=value) ) diff --git a/netbox/core/forms/bulk_edit.py b/netbox/core/forms/bulk_edit.py index 3730c7235..c5713b626 100644 --- a/netbox/core/forms/bulk_edit.py +++ b/netbox/core/forms/bulk_edit.py @@ -5,7 +5,7 @@ from core.choices import DataSourceTypeChoices from core.models import * from netbox.forms import NetBoxModelBulkEditForm from utilities.forms import ( - add_blank_choice, BulkEditNullBooleanSelect, StaticSelect, + add_blank_choice, BulkEditNullBooleanSelect, CommentField, SmallTextarea, StaticSelect, ) __all__ = ( @@ -29,6 +29,10 @@ class DataSourceBulkEditForm(NetBoxModelBulkEditForm): max_length=200, required=False ) + comments = CommentField( + widget=SmallTextarea, + label=_('Comments') + ) parameters = forms.JSONField( required=False ) @@ -39,8 +43,8 @@ class DataSourceBulkEditForm(NetBoxModelBulkEditForm): model = DataSource fieldsets = ( - (None, ('type', 'enabled', 'description', 'parameters', 'ignore_rules')), + (None, ('type', 'enabled', 'description', 'comments', 'parameters', 'ignore_rules')), ) nullable_fields = ( - 'description', 'description', 'parameters', 'parameters', 'ignore_rules', + 'description', 'description', 'parameters', 'comments', 'parameters', 'ignore_rules', ) diff --git a/netbox/core/forms/bulk_import.py b/netbox/core/forms/bulk_import.py index 773e5faa3..94e164ac9 100644 --- a/netbox/core/forms/bulk_import.py +++ b/netbox/core/forms/bulk_import.py @@ -11,5 +11,5 @@ class DataSourceImportForm(NetBoxModelImportForm): class Meta: model = DataSource fields = ( - 'name', 'type', 'url', 'enabled', 'description', 'parameters', 'ignore_rules', + 'name', 'type', 'url', 'enabled', 'description', 'comments', 'parameters', 'ignore_rules', ) diff --git a/netbox/core/forms/model_forms.py b/netbox/core/forms/model_forms.py index cc2f6c0a4..2f58a22a4 100644 --- a/netbox/core/forms/model_forms.py +++ b/netbox/core/forms/model_forms.py @@ -18,7 +18,7 @@ class DataSourceForm(NetBoxModelForm): class Meta: model = DataSource fields = [ - 'name', 'type', 'url', 'enabled', 'description', 'ignore_rules', + 'name', 'type', 'url', 'enabled', 'description', 'comments', 'ignore_rules', ] widgets = { 'type': StaticSelect( diff --git a/netbox/core/migrations/0003_datasource_custom_field_data_datasource_tags.py b/netbox/core/migrations/0003_datasource_custom_field_data_datasource_tags.py new file mode 100644 index 000000000..5011e2e6a --- /dev/null +++ b/netbox/core/migrations/0003_datasource_custom_field_data_datasource_tags.py @@ -0,0 +1,26 @@ +# Generated by Django 4.1.5 on 2023-02-01 20:04 + +from django.db import migrations, models +import taggit.managers +import utilities.json + + +class Migration(migrations.Migration): + + dependencies = [ + ('extras', '0084_staging'), + ('core', '0002_remove_datasource_git_branch_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='datasource', + name='custom_field_data', + field=models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder), + ), + migrations.AddField( + model_name='datasource', + name='tags', + field=taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag'), + ), + ] diff --git a/netbox/core/migrations/0004_datasource_comments.py b/netbox/core/migrations/0004_datasource_comments.py new file mode 100644 index 000000000..ba7459a96 --- /dev/null +++ b/netbox/core/migrations/0004_datasource_comments.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1.5 on 2023-02-01 20:07 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0003_datasource_custom_field_data_datasource_tags'), + ] + + operations = [ + migrations.AddField( + model_name='datasource', + name='comments', + field=models.TextField(blank=True), + ), + ] diff --git a/netbox/core/models/data.py b/netbox/core/models/data.py index d11c51969..90b456e4b 100644 --- a/netbox/core/models/data.py +++ b/netbox/core/models/data.py @@ -14,7 +14,7 @@ from django.utils.module_loading import import_string from django.utils.translation import gettext as _ from extras.models import JobResult -from netbox.models import ChangeLoggedModel +from netbox.models import PrimaryModel from netbox.registry import registry from utilities.files import sha256_hash from utilities.querysets import RestrictedQuerySet @@ -29,7 +29,7 @@ __all__ = ( logger = logging.getLogger('netbox.core.data') -class DataSource(ChangeLoggedModel): +class DataSource(PrimaryModel): """ A remote source, such as a git repository, from which DataFiles are synchronized. """ @@ -55,10 +55,6 @@ class DataSource(ChangeLoggedModel): enabled = models.BooleanField( default=True ) - description = models.CharField( - max_length=200, - blank=True - ) ignore_rules = models.TextField( blank=True, help_text=_("Patterns (one per line) matching files to ignore when syncing") diff --git a/netbox/core/search.py b/netbox/core/search.py index 678f1fbd2..cffa66409 100644 --- a/netbox/core/search.py +++ b/netbox/core/search.py @@ -9,6 +9,7 @@ class DataSourceIndex(SearchIndex): ('name', 100), ('url', 300), ('description', 500), + ('comments', 5000), ) diff --git a/netbox/core/tables/data.py b/netbox/core/tables/data.py index ef9b5c8e2..b0cb64f72 100644 --- a/netbox/core/tables/data.py +++ b/netbox/core/tables/data.py @@ -16,6 +16,9 @@ class DataSourceTable(NetBoxTable): type = columns.ChoiceFieldColumn() status = columns.ChoiceFieldColumn() enabled = columns.BooleanColumn() + tags = columns.TagColumn( + url_name='core:datasource_list' + ) file_count = tables.Column( verbose_name='Files' ) @@ -23,7 +26,7 @@ class DataSourceTable(NetBoxTable): class Meta(NetBoxTable.Meta): model = DataSource fields = ( - 'pk', 'id', 'name', 'type', 'status', 'enabled', 'url', 'description', 'parameters', 'created', + 'pk', 'id', 'name', 'type', 'status', 'enabled', 'url', 'description', 'comments', 'parameters', 'created', 'last_updated', 'file_count', ) default_columns = ('pk', 'name', 'type', 'status', 'enabled', 'description', 'file_count') diff --git a/netbox/templates/core/datasource.html b/netbox/templates/core/datasource.html index 4abfacbbc..168ced700 100644 --- a/netbox/templates/core/datasource.html +++ b/netbox/templates/core/datasource.html @@ -70,6 +70,8 @@ + {% include 'inc/panels/tags.html' %} + {% include 'inc/panels/comments.html' %} {% plugin_left_page object %}