mirror of
https://github.com/netbox-community/netbox.git
synced 2026-04-13 20:49:52 +02:00
Compare commits
4 Commits
main
...
post-raw-s
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b9ab87e38 | ||
|
|
90255a268f | ||
|
|
8418809344 | ||
|
|
b39e1c73c1 |
@@ -6,6 +6,7 @@ from django.dispatch import receiver
|
|||||||
|
|
||||||
from dcim.choices import CableEndChoices, LinkStatusChoices
|
from dcim.choices import CableEndChoices, LinkStatusChoices
|
||||||
from ipam.models import Prefix
|
from ipam.models import Prefix
|
||||||
|
from netbox.signals import post_raw_create
|
||||||
from virtualization.models import Cluster, VMInterface
|
from virtualization.models import Cluster, VMInterface
|
||||||
from wireless.models import WirelessLAN
|
from wireless.models import WirelessLAN
|
||||||
|
|
||||||
@@ -166,6 +167,27 @@ def retrace_cable_paths(instance, **kwargs):
|
|||||||
cablepath.retrace()
|
cablepath.retrace()
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(post_raw_create, sender=Cable)
|
||||||
|
def retrace_cable_paths_after_raw_create(sender, pks, **kwargs):
|
||||||
|
"""
|
||||||
|
When Cables are created via a raw save, the normal Cable.save() path is bypassed,
|
||||||
|
so trace_paths is never sent. Retrace paths for all newly created cables.
|
||||||
|
|
||||||
|
Callers must only send this signal after all CableTerminations for the given cables
|
||||||
|
have been applied. If a cable has no terminations, update_connected_endpoints will
|
||||||
|
find empty termination lists and skip path creation — so this is safe to call even
|
||||||
|
if terminations are absent, but path tracing will have no effect.
|
||||||
|
|
||||||
|
Note: raw=False (the default) is intentional here — we explicitly want
|
||||||
|
update_connected_endpoints to run, unlike during fixture loading (raw=True).
|
||||||
|
"""
|
||||||
|
logger = logging.getLogger('netbox.dcim.cable')
|
||||||
|
for cable in Cable.objects.filter(pk__in=pks):
|
||||||
|
cable._terminations_modified = True
|
||||||
|
trace_paths.send(Cable, instance=cable, created=True)
|
||||||
|
logger.debug(f"Retraced cable paths for Cable {cable.pk}")
|
||||||
|
|
||||||
|
|
||||||
@receiver((post_delete, post_save), sender=PortMapping)
|
@receiver((post_delete, post_save), sender=PortMapping)
|
||||||
def update_passthrough_port_paths(instance, **kwargs):
|
def update_passthrough_port_paths(instance, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -2,3 +2,10 @@ from django.dispatch import Signal
|
|||||||
|
|
||||||
# Signals that a model has completed its clean() method
|
# Signals that a model has completed its clean() method
|
||||||
post_clean = Signal()
|
post_clean = Signal()
|
||||||
|
|
||||||
|
# Sent after objects of a given model are created via raw save.
|
||||||
|
# Expected call signature: post_raw_create.send(sender=MyModel, pks=[...])
|
||||||
|
# Provides: pks (list) - PKs of the newly created objects.
|
||||||
|
# Callers must ensure all related objects (e.g. M2M, dependent rows) are in place
|
||||||
|
# before sending, as receivers may query related data to perform post-create work.
|
||||||
|
post_raw_create = Signal()
|
||||||
|
|||||||
Reference in New Issue
Block a user