2021-04-02 09:17:11 -04:00
|
|
|
from django.db.models.signals import post_delete, post_save
|
2017-01-23 15:31:41 -05:00
|
|
|
from django.dispatch import receiver
|
|
|
|
|
2021-04-02 09:17:11 -04:00
|
|
|
from dcim.signals import rebuild_paths
|
2021-05-06 13:29:52 -04:00
|
|
|
from .models import CircuitTermination
|
2017-01-23 15:31:41 -05:00
|
|
|
|
|
|
|
|
2021-03-18 13:54:05 -04:00
|
|
|
@receiver(post_save, sender=CircuitTermination)
|
2017-01-23 15:31:41 -05:00
|
|
|
def update_circuit(instance, **kwargs):
|
|
|
|
"""
|
2021-03-18 13:54:05 -04:00
|
|
|
When a CircuitTermination has been modified, update its parent Circuit.
|
2017-01-23 15:31:41 -05:00
|
|
|
"""
|
2021-05-06 13:29:52 -04:00
|
|
|
termination_name = f'termination_{instance.term_side.lower()}'
|
2021-10-27 10:02:36 -04:00
|
|
|
instance.circuit.refresh_from_db()
|
2021-05-06 13:29:52 -04:00
|
|
|
setattr(instance.circuit, termination_name, instance)
|
|
|
|
instance.circuit.save()
|
2021-04-02 09:17:11 -04:00
|
|
|
|
|
|
|
|
|
|
|
@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])
|