mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-26 09:16:10 -06:00
Convert DataSource to a primary model
This commit is contained in:
parent
a6e2c4c583
commit
ee378cd0aa
@ -31,7 +31,7 @@ class DataSourceSerializer(NetBoxModelSerializer):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = DataSource
|
model = DataSource
|
||||||
fields = [
|
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',
|
'ignore_rules', 'created', 'last_updated', 'file_count',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ from django.utils.translation import gettext as _
|
|||||||
|
|
||||||
import django_filters
|
import django_filters
|
||||||
|
|
||||||
from netbox.filtersets import ChangeLoggedModelFilterSet
|
from netbox.filtersets import NetBoxModelFilterSet
|
||||||
from .models import *
|
from .models import *
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
@ -12,7 +12,7 @@ __all__ = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class DataSourceFilterSet(ChangeLoggedModelFilterSet):
|
class DataSourceFilterSet(NetBoxModelFilterSet):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = DataSource
|
model = DataSource
|
||||||
@ -23,7 +23,8 @@ class DataSourceFilterSet(ChangeLoggedModelFilterSet):
|
|||||||
return queryset
|
return queryset
|
||||||
return queryset.filter(
|
return queryset.filter(
|
||||||
Q(name__icontains=value) |
|
Q(name__icontains=value) |
|
||||||
Q(description__icontains=value)
|
Q(description__icontains=value) |
|
||||||
|
Q(comments__icontains=value)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ from core.choices import DataSourceTypeChoices
|
|||||||
from core.models import *
|
from core.models import *
|
||||||
from netbox.forms import NetBoxModelBulkEditForm
|
from netbox.forms import NetBoxModelBulkEditForm
|
||||||
from utilities.forms import (
|
from utilities.forms import (
|
||||||
add_blank_choice, BulkEditNullBooleanSelect, StaticSelect,
|
add_blank_choice, BulkEditNullBooleanSelect, CommentField, SmallTextarea, StaticSelect,
|
||||||
)
|
)
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
@ -29,6 +29,10 @@ class DataSourceBulkEditForm(NetBoxModelBulkEditForm):
|
|||||||
max_length=200,
|
max_length=200,
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
|
comments = CommentField(
|
||||||
|
widget=SmallTextarea,
|
||||||
|
label=_('Comments')
|
||||||
|
)
|
||||||
parameters = forms.JSONField(
|
parameters = forms.JSONField(
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
@ -39,8 +43,8 @@ class DataSourceBulkEditForm(NetBoxModelBulkEditForm):
|
|||||||
|
|
||||||
model = DataSource
|
model = DataSource
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
(None, ('type', 'enabled', 'description', 'parameters', 'ignore_rules')),
|
(None, ('type', 'enabled', 'description', 'comments', 'parameters', 'ignore_rules')),
|
||||||
)
|
)
|
||||||
nullable_fields = (
|
nullable_fields = (
|
||||||
'description', 'description', 'parameters', 'parameters', 'ignore_rules',
|
'description', 'description', 'parameters', 'comments', 'parameters', 'ignore_rules',
|
||||||
)
|
)
|
||||||
|
@ -11,5 +11,5 @@ class DataSourceImportForm(NetBoxModelImportForm):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = DataSource
|
model = DataSource
|
||||||
fields = (
|
fields = (
|
||||||
'name', 'type', 'url', 'enabled', 'description', 'parameters', 'ignore_rules',
|
'name', 'type', 'url', 'enabled', 'description', 'comments', 'parameters', 'ignore_rules',
|
||||||
)
|
)
|
||||||
|
@ -18,7 +18,7 @@ class DataSourceForm(NetBoxModelForm):
|
|||||||
class Meta:
|
class Meta:
|
||||||
model = DataSource
|
model = DataSource
|
||||||
fields = [
|
fields = [
|
||||||
'name', 'type', 'url', 'enabled', 'description', 'ignore_rules',
|
'name', 'type', 'url', 'enabled', 'description', 'comments', 'ignore_rules',
|
||||||
]
|
]
|
||||||
widgets = {
|
widgets = {
|
||||||
'type': StaticSelect(
|
'type': StaticSelect(
|
||||||
|
@ -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'),
|
||||||
|
),
|
||||||
|
]
|
18
netbox/core/migrations/0004_datasource_comments.py
Normal file
18
netbox/core/migrations/0004_datasource_comments.py
Normal file
@ -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),
|
||||||
|
),
|
||||||
|
]
|
@ -14,7 +14,7 @@ from django.utils.module_loading import import_string
|
|||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
from extras.models import JobResult
|
from extras.models import JobResult
|
||||||
from netbox.models import ChangeLoggedModel
|
from netbox.models import PrimaryModel
|
||||||
from netbox.registry import registry
|
from netbox.registry import registry
|
||||||
from utilities.files import sha256_hash
|
from utilities.files import sha256_hash
|
||||||
from utilities.querysets import RestrictedQuerySet
|
from utilities.querysets import RestrictedQuerySet
|
||||||
@ -29,7 +29,7 @@ __all__ = (
|
|||||||
logger = logging.getLogger('netbox.core.data')
|
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.
|
A remote source, such as a git repository, from which DataFiles are synchronized.
|
||||||
"""
|
"""
|
||||||
@ -55,10 +55,6 @@ class DataSource(ChangeLoggedModel):
|
|||||||
enabled = models.BooleanField(
|
enabled = models.BooleanField(
|
||||||
default=True
|
default=True
|
||||||
)
|
)
|
||||||
description = models.CharField(
|
|
||||||
max_length=200,
|
|
||||||
blank=True
|
|
||||||
)
|
|
||||||
ignore_rules = models.TextField(
|
ignore_rules = models.TextField(
|
||||||
blank=True,
|
blank=True,
|
||||||
help_text=_("Patterns (one per line) matching files to ignore when syncing")
|
help_text=_("Patterns (one per line) matching files to ignore when syncing")
|
||||||
|
@ -9,6 +9,7 @@ class DataSourceIndex(SearchIndex):
|
|||||||
('name', 100),
|
('name', 100),
|
||||||
('url', 300),
|
('url', 300),
|
||||||
('description', 500),
|
('description', 500),
|
||||||
|
('comments', 5000),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,6 +16,9 @@ class DataSourceTable(NetBoxTable):
|
|||||||
type = columns.ChoiceFieldColumn()
|
type = columns.ChoiceFieldColumn()
|
||||||
status = columns.ChoiceFieldColumn()
|
status = columns.ChoiceFieldColumn()
|
||||||
enabled = columns.BooleanColumn()
|
enabled = columns.BooleanColumn()
|
||||||
|
tags = columns.TagColumn(
|
||||||
|
url_name='core:datasource_list'
|
||||||
|
)
|
||||||
file_count = tables.Column(
|
file_count = tables.Column(
|
||||||
verbose_name='Files'
|
verbose_name='Files'
|
||||||
)
|
)
|
||||||
@ -23,7 +26,7 @@ class DataSourceTable(NetBoxTable):
|
|||||||
class Meta(NetBoxTable.Meta):
|
class Meta(NetBoxTable.Meta):
|
||||||
model = DataSource
|
model = DataSource
|
||||||
fields = (
|
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',
|
'last_updated', 'file_count',
|
||||||
)
|
)
|
||||||
default_columns = ('pk', 'name', 'type', 'status', 'enabled', 'description', 'file_count')
|
default_columns = ('pk', 'name', 'type', 'status', 'enabled', 'description', 'file_count')
|
||||||
|
@ -70,6 +70,8 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% include 'inc/panels/tags.html' %}
|
||||||
|
{% include 'inc/panels/comments.html' %}
|
||||||
{% plugin_left_page object %}
|
{% plugin_left_page object %}
|
||||||
</div>
|
</div>
|
||||||
<div class="col col-md-6">
|
<div class="col col-md-6">
|
||||||
|
Loading…
Reference in New Issue
Block a user