1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Rebuild CablePaths when a CircuitTermination is modified

This commit is contained in:
Jeremy Stretch
2021-04-02 09:17:11 -04:00
parent 5e4432b9ad
commit b77c228853
2 changed files with 36 additions and 4 deletions

View File

@ -1,7 +1,8 @@
from django.db.models.signals import post_save
from django.db.models.signals import post_delete, post_save
from django.dispatch import receiver
from django.utils import timezone
from dcim.signals import rebuild_paths
from .models import Circuit, CircuitTermination
@ -15,3 +16,14 @@ def update_circuit(instance, **kwargs):
f'termination_{instance.term_side.lower()}': instance.pk,
}
Circuit.objects.filter(pk=instance.circuit_id).update(**fields)
@receiver((post_save, post_delete), sender=CircuitTermination)
def rebuild_cablepaths(instance, raw=False, **kwargs):
"""
Rebuild any CablePaths which traverse the peer CircuitTermination.
"""
if not raw:
peer_termination = instance.get_peer_termination()
if peer_termination:
rebuild_paths(peer_termination)