mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-07 04:27:27 -06:00
Compare commits
20 Commits
20923-dcim
...
acef50a693
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
acef50a693 | ||
|
|
77b389f105 | ||
|
|
cf16a29ad3 | ||
|
|
544c97d923 | ||
|
|
77ee6baa23 | ||
|
|
09d1049267 | ||
|
|
93e5f919ba | ||
|
|
929d024003 | ||
|
|
e4b614038e | ||
|
|
3016b1d90b | ||
|
|
57b47dc1ea | ||
|
|
da4c669312 | ||
|
|
71f707b7ac | ||
|
|
e11508dd6c | ||
|
|
5b5b5c8909 | ||
|
|
a49869af42 | ||
|
|
2e0ff04f84 | ||
|
|
bfeba36514 | ||
|
|
111aca115b | ||
|
|
b4160ad59b |
@@ -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()
|
||||
|
||||
@@ -119,7 +119,9 @@ def process_event_rules(event_rules, object_type, event_type, data, username=Non
|
||||
if snapshots:
|
||||
params["snapshots"] = snapshots
|
||||
if request:
|
||||
params["request"] = copy_safe_request(request)
|
||||
# Exclude FILES - webhooks don't need uploaded files,
|
||||
# which can cause pickle errors with Pillow.
|
||||
params["request"] = copy_safe_request(request, include_files=False)
|
||||
|
||||
# Enqueue the task
|
||||
rq_queue.enqueue(
|
||||
|
||||
@@ -35,27 +35,34 @@ class NetBoxFakeRequest:
|
||||
# Utility functions
|
||||
#
|
||||
|
||||
def copy_safe_request(request):
|
||||
def copy_safe_request(request, include_files=True):
|
||||
"""
|
||||
Copy selected attributes from a request object into a new fake request object. This is needed in places where
|
||||
thread safe pickling of the useful request data is needed.
|
||||
|
||||
Args:
|
||||
request: The original request object
|
||||
include_files: Whether to include request.FILES.
|
||||
"""
|
||||
meta = {
|
||||
k: request.META[k]
|
||||
for k in HTTP_REQUEST_META_SAFE_COPY
|
||||
if k in request.META and isinstance(request.META[k], str)
|
||||
}
|
||||
return NetBoxFakeRequest({
|
||||
data = {
|
||||
'META': meta,
|
||||
'COOKIES': request.COOKIES,
|
||||
'POST': request.POST,
|
||||
'GET': request.GET,
|
||||
'FILES': request.FILES,
|
||||
'user': request.user,
|
||||
'method': request.method,
|
||||
'path': request.path,
|
||||
'id': getattr(request, 'id', None), # UUID assigned by middleware
|
||||
})
|
||||
}
|
||||
if include_files:
|
||||
data['FILES'] = request.FILES
|
||||
|
||||
return NetBoxFakeRequest(data)
|
||||
|
||||
|
||||
def get_client_ip(request, additional_headers=()):
|
||||
|
||||
Reference in New Issue
Block a user