mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-26 09:16:10 -06:00
Add status field to DataSource
This commit is contained in:
parent
41607f9a52
commit
cdc18868a5
@ -12,23 +12,37 @@ __all__ = (
|
|||||||
|
|
||||||
|
|
||||||
class DataSourceSerializer(NetBoxModelSerializer):
|
class DataSourceSerializer(NetBoxModelSerializer):
|
||||||
url = serializers.HyperlinkedIdentityField(view_name='core-api:datasource-detail')
|
url = serializers.HyperlinkedIdentityField(
|
||||||
type = ChoiceField(choices=DataSourceTypeChoices, required=False)
|
view_name='core-api:datasource-detail'
|
||||||
|
)
|
||||||
|
type = ChoiceField(
|
||||||
|
choices=DataSourceTypeChoices
|
||||||
|
)
|
||||||
|
status = ChoiceField(
|
||||||
|
choices=DataSourceStatusChoices,
|
||||||
|
read_only=True
|
||||||
|
)
|
||||||
|
|
||||||
# Related object counts
|
# Related object counts
|
||||||
file_count = serializers.IntegerField(read_only=True)
|
file_count = serializers.IntegerField(
|
||||||
|
read_only=True
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = DataSource
|
model = DataSource
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display', 'name', 'type', 'url', 'enabled', 'description', 'git_branch', 'ignore_rules',
|
'id', 'url', 'display', 'name', 'type', 'url', 'enabled', 'status', 'description', 'git_branch',
|
||||||
'username', 'password', 'created', 'last_updated', 'file_count',
|
'ignore_rules', 'username', 'password', 'created', 'last_updated', 'file_count',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class DataFileSerializer(NetBoxModelSerializer):
|
class DataFileSerializer(NetBoxModelSerializer):
|
||||||
url = serializers.HyperlinkedIdentityField(view_name='core-api:datafile-detail')
|
url = serializers.HyperlinkedIdentityField(
|
||||||
source = NestedDataSourceSerializer(read_only=True)
|
view_name='core-api:datafile-detail'
|
||||||
|
)
|
||||||
|
source = NestedDataSourceSerializer(
|
||||||
|
read_only=True
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = DataFile
|
model = DataFile
|
||||||
|
@ -13,9 +13,24 @@ class DataSourceTypeChoices(ChoiceSet):
|
|||||||
FTP = 'ftp'
|
FTP = 'ftp'
|
||||||
GIT = 'git'
|
GIT = 'git'
|
||||||
|
|
||||||
CHOICES = [
|
CHOICES = (
|
||||||
(LOCAL, _('Local')),
|
(LOCAL, _('Local')),
|
||||||
(HTTP, _('HTTP(S)')),
|
(HTTP, _('HTTP(S)')),
|
||||||
(FTP, _('FTP(S)')),
|
(FTP, _('FTP(S)')),
|
||||||
(GIT, _('Git')),
|
(GIT, _('Git')),
|
||||||
]
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class DataSourceStatusChoices(ChoiceSet):
|
||||||
|
|
||||||
|
NEW = 'new'
|
||||||
|
SYNCING = 'syncing'
|
||||||
|
COMPLETED = 'completed'
|
||||||
|
FAILED = 'failed'
|
||||||
|
|
||||||
|
CHOICES = (
|
||||||
|
(NEW, _('New')),
|
||||||
|
(SYNCING, _('Syncing')),
|
||||||
|
(COMPLETED, _('Completed')),
|
||||||
|
(FAILED, _('Failed')),
|
||||||
|
)
|
||||||
|
@ -15,7 +15,7 @@ class DataSourceFilterSet(django_filters.FilterSet):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = DataSource
|
model = DataSource
|
||||||
fields = ('id', 'name', 'type', 'git_branch', 'username')
|
fields = ('id', 'name', 'type', 'enabled', 'status', 'git_branch', 'username')
|
||||||
|
|
||||||
def search(self, queryset, name, value):
|
def search(self, queryset, name, value):
|
||||||
if not value.strip():
|
if not value.strip():
|
||||||
|
@ -3,7 +3,9 @@ from django import forms
|
|||||||
from core.choices import *
|
from core.choices import *
|
||||||
from core.models import *
|
from core.models import *
|
||||||
from netbox.forms import NetBoxModelFilterSetForm
|
from netbox.forms import NetBoxModelFilterSetForm
|
||||||
from utilities.forms import DynamicModelMultipleChoiceField, MultipleChoiceField
|
from utilities.forms import (
|
||||||
|
BOOLEAN_WITH_BLANK_CHOICES, DynamicModelMultipleChoiceField, MultipleChoiceField, StaticSelect,
|
||||||
|
)
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'DataFileFilterForm',
|
'DataFileFilterForm',
|
||||||
@ -46,6 +48,16 @@ class DataFileFilterForm(NetBoxModelFilterSetForm):
|
|||||||
choices=DataSourceTypeChoices,
|
choices=DataSourceTypeChoices,
|
||||||
required=False
|
required=False
|
||||||
)
|
)
|
||||||
|
enabled = forms.NullBooleanField(
|
||||||
|
required=False,
|
||||||
|
widget=StaticSelect(
|
||||||
|
choices=BOOLEAN_WITH_BLANK_CHOICES
|
||||||
|
)
|
||||||
|
)
|
||||||
|
status = MultipleChoiceField(
|
||||||
|
choices=DataSourceStatusChoices,
|
||||||
|
required=False
|
||||||
|
)
|
||||||
git_branch = forms.CharField(
|
git_branch = forms.CharField(
|
||||||
max_length=100,
|
max_length=100,
|
||||||
required=False
|
required=False
|
||||||
|
18
netbox/core/migrations/0004_datasource_status.py
Normal file
18
netbox/core/migrations/0004_datasource_status.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.1.5 on 2023-01-27 14:09
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('core', '0003_datasource_created_datasource_last_updated'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='datasource',
|
||||||
|
name='status',
|
||||||
|
field=models.CharField(default='new', editable=False, max_length=50),
|
||||||
|
),
|
||||||
|
]
|
@ -40,6 +40,12 @@ class DataSource(ChangeLoggedModel):
|
|||||||
max_length=200,
|
max_length=200,
|
||||||
verbose_name=_('URL')
|
verbose_name=_('URL')
|
||||||
)
|
)
|
||||||
|
status = models.CharField(
|
||||||
|
max_length=50,
|
||||||
|
choices=DataSourceStatusChoices,
|
||||||
|
default=DataSourceStatusChoices.NEW,
|
||||||
|
editable=False
|
||||||
|
)
|
||||||
enabled = models.BooleanField(
|
enabled = models.BooleanField(
|
||||||
default=True
|
default=True
|
||||||
)
|
)
|
||||||
|
@ -19,6 +19,10 @@
|
|||||||
<th scope="row">Type</th>
|
<th scope="row">Type</th>
|
||||||
<td>{{ object.get_type_display }}</td>
|
<td>{{ object.get_type_display }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th scope="row">Status</th>
|
||||||
|
<td>{{ object.get_status_display }}</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Enabled</th>
|
<th scope="row">Enabled</th>
|
||||||
<td>{% checkmark object.enabled %}</td>
|
<td>{% checkmark object.enabled %}</td>
|
||||||
|
Loading…
Reference in New Issue
Block a user