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

Fix tracing from front/rear ports

Jeremy Stretch 5 лет назад
Родитель
Сommit
d560e2da93
2 измененных файлов с 49 добавлено и 47 удалено
  1. 3 2
      netbox/dcim/views.py
  2. 46 45
      netbox/templates/dcim/cable_trace.html

+ 3 - 2
netbox/dcim/views.py

@@ -2026,6 +2026,7 @@ class PathTraceView(ObjectView):
         # If tracing a PathEndpoint, locate the CablePath (if one exists) by its origin
         # If tracing a PathEndpoint, locate the CablePath (if one exists) by its origin
         if isinstance(obj, PathEndpoint):
         if isinstance(obj, PathEndpoint):
             path = obj._path
             path = obj._path
+
         # Otherwise, find all CablePaths which traverse the specified object
         # Otherwise, find all CablePaths which traverse the specified object
         else:
         else:
             related_paths = CablePath.objects.filter(path__contains=obj).prefetch_related('origin')
             related_paths = CablePath.objects.filter(path__contains=obj).prefetch_related('origin')
@@ -2041,9 +2042,9 @@ class PathTraceView(ObjectView):
 
 
         return render(request, 'dcim/cable_trace.html', {
         return render(request, 'dcim/cable_trace.html', {
             'obj': obj,
             'obj': obj,
-            'path': obj.trace(),
+            'path': path,
             'related_paths': related_paths,
             'related_paths': related_paths,
-            'total_length': path.get_total_length(),
+            'total_length': path.get_total_length() if path else None,
         })
         })
 
 
 
 

+ 46 - 45
netbox/templates/dcim/cable_trace.html

@@ -8,58 +8,59 @@
 {% block content %}
 {% block content %}
     <div class="row">
     <div class="row">
         <div class="col-md-5 col-sm-12 text-center">
         <div class="col-md-5 col-sm-12 text-center">
-            {% for near_end, cable, far_end in path %}
+            {% with traced_path=path.origin.trace %}
+                {% for near_end, cable, far_end in traced_path %}
 
 
-                {# Near end #}
-                {% if near_end.device %}
-                    {% include 'dcim/trace/device.html' with device=near_end.device %}
-                    {% include 'dcim/trace/termination.html' with termination=near_end %}
-                {% elif near_end.power_panel %}
-                    {% include 'dcim/trace/powerfeed.html' with powerfeed=near_end %}
-                {% elif near_end.circuit %}
-                    {% include 'dcim/trace/circuit.html' with circuit=near_end.circuit %}
-                    {% include 'dcim/trace/termination.html' with termination=near_end %}
-                {% else %}
-                    <h3 class="text-danger text-center">Split Paths!</h3>
-                    {# TODO: Present the user with successive paths to choose from #}
-                {% endif %}
-
-                {# Cable #}
-                {% if cable %}
-                    <div class="row">
-                        {% include 'dcim/trace/cable.html' %}
-                    </div>
-                {% endif %}
+                    {# Near end #}
+                    {% if near_end.device %}
+                        {% include 'dcim/trace/device.html' with device=near_end.device %}
+                        {% include 'dcim/trace/termination.html' with termination=near_end %}
+                    {% elif near_end.power_panel %}
+                        {% include 'dcim/trace/powerfeed.html' with powerfeed=near_end %}
+                    {% elif near_end.circuit %}
+                        {% include 'dcim/trace/circuit.html' with circuit=near_end.circuit %}
+                        {% include 'dcim/trace/termination.html' with termination=near_end %}
+                    {% else %}
+                        <h3 class="text-danger text-center">Split Paths!</h3>
+                        {# TODO: Present the user with successive paths to choose from #}
+                    {% endif %}
 
 
-                {# Far end #}
-                {% if far_end.device %}
-                    {% include 'dcim/trace/termination.html' with termination=far_end %}
-                    {% if forloop.last %}
-                        {% include 'dcim/trace/device.html' with device=far_end.device %}
+                    {# Cable #}
+                    {% if cable %}
+                        <div class="row">
+                            {% include 'dcim/trace/cable.html' %}
+                        </div>
                     {% endif %}
                     {% endif %}
-                {% elif far_end.power_panel %}
-                    {% include 'dcim/trace/powerfeed.html' with powerfeed=far_end %}
-                {% elif far_end.circuit %}
-                    {% include 'dcim/trace/termination.html' with termination=far_end %}
-                    {% if forloop.last %}
-                        {% include 'dcim/trace/circuit.html' with circuit=far_end.circuit %}
+
+                    {# Far end #}
+                    {% if far_end.device %}
+                        {% include 'dcim/trace/termination.html' with termination=far_end %}
+                        {% if forloop.last %}
+                            {% include 'dcim/trace/device.html' with device=far_end.device %}
+                        {% endif %}
+                    {% elif far_end.power_panel %}
+                        {% include 'dcim/trace/powerfeed.html' with powerfeed=far_end %}
+                    {% elif far_end.circuit %}
+                        {% include 'dcim/trace/termination.html' with termination=far_end %}
+                        {% if forloop.last %}
+                            {% include 'dcim/trace/circuit.html' with circuit=far_end.circuit %}
+                        {% endif %}
                     {% endif %}
                     {% endif %}
-                {% endif %}
 
 
-                {% if forloop.last and far_end %}
-                    <div class="row">
-                        <div class="text-center">
-                            <h3 class="text-success text-center">Trace completed!</h3>
-                            <h5>Total segments: {{ path|length }}</h5>
-                            {% if total_length %}
-                                <h5>Total length: {{ total_length|floatformat:"-2" }} Meters<h5>
-                            {% endif %}
+                    {% if forloop.last and far_end %}
+                        <div class="row">
+                            <div class="text-center">
+                                <h3 class="text-success text-center">Trace completed!</h3>
+                                <h5>Total segments: {{ traced_path|length }}</h5>
+                                {% if total_length %}
+                                    <h5>Total length: {{ total_length|floatformat:"-2" }} Meters<h5>
+                                {% endif %}
+                            </div>
                         </div>
                         </div>
-                    </div>
-                {% endif %}
-
-            {% endfor %}
+                    {% endif %}
 
 
+                {% endfor %}
+            {% endwith %}
         </div>
         </div>
         <div class="col-md-7 col-sm-12">
         <div class="col-md-7 col-sm-12">