mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-17 12:42:52 -06:00
Merge pull request #5672 from cpmills1975/5650-render-incomplete-lengths
Indicate when cable length is not definitive
This commit is contained in:
commit
a135396d7b
@ -480,13 +480,17 @@ class CablePath(models.Model):
|
|||||||
|
|
||||||
def get_total_length(self):
|
def get_total_length(self):
|
||||||
"""
|
"""
|
||||||
Return the sum of the length of each cable in the path.
|
Return a tuple containing the sum of the length of each cable in the path
|
||||||
|
and a flag indicating whether the length is definitive.
|
||||||
"""
|
"""
|
||||||
cable_ids = [
|
cable_ids = [
|
||||||
# Starting from the first element, every third element in the path should be a Cable
|
# Starting from the first element, every third element in the path should be a Cable
|
||||||
decompile_path_node(self.path[i])[1] for i in range(0, len(self.path), 3)
|
decompile_path_node(self.path[i])[1] for i in range(0, len(self.path), 3)
|
||||||
]
|
]
|
||||||
return Cable.objects.filter(id__in=cable_ids).aggregate(total=Sum('_abs_length'))['total']
|
cables = Cable.objects.filter(id__in=cable_ids, _abs_length__isnull=False)
|
||||||
|
total_length = cables.aggregate(total=Sum('_abs_length'))['total']
|
||||||
|
is_definitive = len(cables) == len(cable_ids)
|
||||||
|
return (total_length, is_definitive)
|
||||||
|
|
||||||
def get_split_nodes(self):
|
def get_split_nodes(self):
|
||||||
"""
|
"""
|
||||||
|
@ -2134,10 +2134,14 @@ class PathTraceView(generic.ObjectView):
|
|||||||
else:
|
else:
|
||||||
path = related_paths.first()
|
path = related_paths.first()
|
||||||
|
|
||||||
|
# Get the total length of the cable and whether the length is definitive (fully defined)
|
||||||
|
total_length, is_definitive = path.get_total_length if path else (None, False)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'path': path,
|
'path': path,
|
||||||
'related_paths': related_paths,
|
'related_paths': related_paths,
|
||||||
'total_length': path.get_total_length() if path else None,
|
'total_length': total_length,
|
||||||
|
'is_definitive': is_definitive
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@
|
|||||||
<h5>Total segments: {{ traced_path|length }}</h5>
|
<h5>Total segments: {{ traced_path|length }}</h5>
|
||||||
<h5>Total length:
|
<h5>Total length:
|
||||||
{% if total_length %}
|
{% if total_length %}
|
||||||
{{ total_length|floatformat:"-2" }} Meters /
|
{% if not is_definitive %}>{% endif %}{{ total_length|floatformat:"-2" }} Meters /
|
||||||
{{ total_length|meters_to_feet|floatformat:"-2" }} Feet
|
{{ total_length|meters_to_feet|floatformat:"-2" }} Feet
|
||||||
{% else %}
|
{% else %}
|
||||||
<span class="text-muted">N/A</span>
|
<span class="text-muted">N/A</span>
|
||||||
|
Loading…
Reference in New Issue
Block a user