mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-12 11:29:36 -06:00
Merge cf16a29ad3 into 269112a565
This commit is contained in:
commit
0ce7e16980
@ -13,6 +13,7 @@ class DataSourceStatusChoices(ChoiceSet):
|
|||||||
SYNCING = 'syncing'
|
SYNCING = 'syncing'
|
||||||
COMPLETED = 'completed'
|
COMPLETED = 'completed'
|
||||||
FAILED = 'failed'
|
FAILED = 'failed'
|
||||||
|
READY = 'ready'
|
||||||
|
|
||||||
CHOICES = (
|
CHOICES = (
|
||||||
(NEW, _('New'), 'blue'),
|
(NEW, _('New'), 'blue'),
|
||||||
@ -20,6 +21,7 @@ class DataSourceStatusChoices(ChoiceSet):
|
|||||||
(SYNCING, _('Syncing'), 'cyan'),
|
(SYNCING, _('Syncing'), 'cyan'),
|
||||||
(COMPLETED, _('Completed'), 'green'),
|
(COMPLETED, _('Completed'), 'green'),
|
||||||
(FAILED, _('Failed'), 'red'),
|
(FAILED, _('Failed'), 'red'),
|
||||||
|
(READY, _('Ready'), 'green'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -16,6 +16,7 @@ from utilities.forms import get_field_value
|
|||||||
from utilities.forms.fields import CommentField, JSONField
|
from utilities.forms.fields import CommentField, JSONField
|
||||||
from utilities.forms.rendering import FieldSet
|
from utilities.forms.rendering import FieldSet
|
||||||
from utilities.forms.widgets import HTMXSelect
|
from utilities.forms.widgets import HTMXSelect
|
||||||
|
from core.choices import DataSourceStatusChoices
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'ConfigRevisionForm',
|
'ConfigRevisionForm',
|
||||||
@ -79,14 +80,28 @@ class DataSourceForm(NetBoxModelForm):
|
|||||||
if self.instance and self.instance.parameters:
|
if self.instance and self.instance.parameters:
|
||||||
self.fields[field_name].initial = self.instance.parameters.get(name)
|
self.fields[field_name].initial = self.instance.parameters.get(name)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
|
||||||
|
|
||||||
|
def save(self, *args, **kwargs):
|
||||||
parameters = {}
|
parameters = {}
|
||||||
for name in self.fields:
|
for name in self.fields:
|
||||||
if name.startswith('backend_'):
|
if name.startswith('backend_'):
|
||||||
parameters[name[8:]] = self.cleaned_data[name]
|
parameters[name[8:]] = self.cleaned_data[name]
|
||||||
self.instance.parameters = parameters
|
self.instance.parameters = parameters
|
||||||
|
|
||||||
|
# Determine initial status based on new/existing instance
|
||||||
|
if not self.instance.pk:
|
||||||
|
# New instance
|
||||||
|
object_status = DataSourceStatusChoices.NEW
|
||||||
|
else:
|
||||||
|
# Existing instance
|
||||||
|
if not self.cleaned_data.get("sync_interval"):
|
||||||
|
object_status = DataSourceStatusChoices.READY
|
||||||
|
else:
|
||||||
|
object_status = self.instance.status
|
||||||
|
|
||||||
|
# # Final override only if the user explicitly provided a status
|
||||||
|
self.instance.status = object_status
|
||||||
|
|
||||||
return super().save(*args, **kwargs)
|
return super().save(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -111,10 +111,7 @@ class DataSource(JobsMixin, PrimaryModel):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def ready_for_sync(self):
|
def ready_for_sync(self):
|
||||||
return self.enabled and self.status not in (
|
return self.enabled and self.status != DataSourceStatusChoices.SYNCING
|
||||||
DataSourceStatusChoices.QUEUED,
|
|
||||||
DataSourceStatusChoices.SYNCING
|
|
||||||
)
|
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
super().clean()
|
super().clean()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user