Просмотр исходного кода

Update & restore rebuild_paths()

jeremystretch 3 лет назад
Родитель
Сommit
d89f067c00
3 измененных файлов с 12 добавлено и 11 удалено
  1. 2 2
      netbox/circuits/signals.py
  2. 2 2
      netbox/dcim/signals.py
  3. 8 7
      netbox/dcim/utils.py

+ 2 - 2
netbox/circuits/signals.py

@@ -23,5 +23,5 @@ def rebuild_cablepaths(instance, raw=False, **kwargs):
     """
     """
     if not raw:
     if not raw:
         peer_termination = instance.get_peer_termination()
         peer_termination = instance.get_peer_termination()
-        # if peer_termination:
-        #     rebuild_paths(peer_termination)
+        if peer_termination:
+            rebuild_paths([peer_termination])

+ 2 - 2
netbox/dcim/signals.py

@@ -100,8 +100,8 @@ def update_connected_endpoints(instance, created, raw=False, **kwargs):
             # Examine type of first termination to determine object type (all must be the same)
             # Examine type of first termination to determine object type (all must be the same)
             if isinstance(terms[0], PathEndpoint):
             if isinstance(terms[0], PathEndpoint):
                 create_cablepath(terms)
                 create_cablepath(terms)
-            # else:
-            #     rebuild_paths(terms)
+            else:
+                rebuild_paths(terms)
     # elif instance.status != instance._orig_status:
     # elif instance.status != instance._orig_status:
     #     # We currently don't support modifying either termination of an existing Cable. (This
     #     # We currently don't support modifying either termination of an existing Cable. (This
     #     # may change in the future.) However, we do need to capture status changes and update
     #     # may change in the future.) However, we do need to capture status changes and update

+ 8 - 7
netbox/dcim/utils.py

@@ -52,16 +52,17 @@ def create_cablepath(terminations):
         cp.save()
         cp.save()
 
 
 
 
-def rebuild_paths(obj):
+def rebuild_paths(terminations):
     """
     """
     Rebuild all CablePaths which traverse the specified node
     Rebuild all CablePaths which traverse the specified node
     """
     """
     from dcim.models import CablePath
     from dcim.models import CablePath
 
 
-    cable_paths = CablePath.objects.filter(path__contains=obj)
+    for obj in terminations:
+        cable_paths = CablePath.objects.filter(_nodes__contains=obj)
 
 
-    with transaction.atomic():
-        for cp in cable_paths:
-            cp.delete()
-            if cp.origin:
-                create_cablepath(cp.origin)
+        with transaction.atomic():
+            for cp in cable_paths:
+                cp.delete()
+                origins = [path_node_to_object(node) for node in cp.path[0]]
+                create_cablepath(origins)