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

28 lines
907 B
Python
Raw Permalink Normal View History

from django.db.models.signals import post_delete, post_save
from django.dispatch import receiver
from dcim.signals import rebuild_paths
from .models import CircuitTermination
2021-03-18 13:54:05 -04:00
@receiver(post_save, sender=CircuitTermination)
def update_circuit(instance, **kwargs):
"""
2021-03-18 13:54:05 -04:00
When a CircuitTermination has been modified, update its parent Circuit.
"""
termination_name = f'termination_{instance.term_side.lower()}'
instance.circuit.refresh_from_db()
setattr(instance.circuit, termination_name, instance)
instance.circuit.save()
@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()
2022-05-10 10:30:58 -04:00
if peer_termination:
rebuild_paths([peer_termination])