mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-10 18:39:36 -06:00
Merge cf16a29ad3 into 269112a565
This commit is contained in:
commit
0ce7e16980
@ -13,6 +13,7 @@ class DataSourceStatusChoices(ChoiceSet):
|
||||
SYNCING = 'syncing'
|
||||
COMPLETED = 'completed'
|
||||
FAILED = 'failed'
|
||||
READY = 'ready'
|
||||
|
||||
CHOICES = (
|
||||
(NEW, _('New'), 'blue'),
|
||||
@ -20,6 +21,7 @@ class DataSourceStatusChoices(ChoiceSet):
|
||||
(SYNCING, _('Syncing'), 'cyan'),
|
||||
(COMPLETED, _('Completed'), 'green'),
|
||||
(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.rendering import FieldSet
|
||||
from utilities.forms.widgets import HTMXSelect
|
||||
from core.choices import DataSourceStatusChoices
|
||||
|
||||
__all__ = (
|
||||
'ConfigRevisionForm',
|
||||
@ -79,14 +80,28 @@ class DataSourceForm(NetBoxModelForm):
|
||||
if self.instance and self.instance.parameters:
|
||||
self.fields[field_name].initial = self.instance.parameters.get(name)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
parameters = {}
|
||||
for name in self.fields:
|
||||
if name.startswith('backend_'):
|
||||
parameters[name[8:]] = self.cleaned_data[name]
|
||||
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)
|
||||
|
||||
|
||||
|
||||
@ -111,10 +111,7 @@ class DataSource(JobsMixin, PrimaryModel):
|
||||
|
||||
@property
|
||||
def ready_for_sync(self):
|
||||
return self.enabled and self.status not in (
|
||||
DataSourceStatusChoices.QUEUED,
|
||||
DataSourceStatusChoices.SYNCING
|
||||
)
|
||||
return self.enabled and self.status != DataSourceStatusChoices.SYNCING
|
||||
|
||||
def clean(self):
|
||||
super().clean()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user