Merge pull request #3859 from hSaria/3440-total-cable-length

Fixes #3440: Total cable trace length
This commit is contained in:
Jeremy Stretch 2020-01-09 10:55:30 -05:00 committed by GitHub
commit 92ec4bd22f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 2 deletions

View File

@ -6,6 +6,7 @@
* [#2589](https://github.com/netbox-community/netbox/issues/2589) - Toggle for showing available prefixes/ip addresses * [#2589](https://github.com/netbox-community/netbox/issues/2589) - Toggle for showing available prefixes/ip addresses
* [#3090](https://github.com/netbox-community/netbox/issues/3090) - Add filter field for device interfaces * [#3090](https://github.com/netbox-community/netbox/issues/3090) - Add filter field for device interfaces
* [#3187](https://github.com/netbox-community/netbox/issues/3187) - Add rack selection field to rack elevations * [#3187](https://github.com/netbox-community/netbox/issues/3187) - Add rack selection field to rack elevations
* [#3440](https://github.com/netbox-community/netbox/issues/3440) - Add total length to cable trace
* [#3851](https://github.com/netbox-community/netbox/issues/3851) - Allow passing initial data to custom script forms * [#3851](https://github.com/netbox-community/netbox/issues/3851) - Allow passing initial data to custom script forms
## Bug Fixes ## Bug Fixes

View File

@ -2950,6 +2950,8 @@ class Cable(ChangeLoggedModel):
# Store the given length (if any) in meters for use in database ordering # Store the given length (if any) in meters for use in database ordering
if self.length and self.length_unit: if self.length and self.length_unit:
self._abs_length = to_meters(self.length, self.length_unit) self._abs_length = to_meters(self.length, self.length_unit)
else:
self._abs_length = None
# Store the parent Device for the A and B terminations (if applicable) to enable filtering # Store the parent Device for the A and B terminations (if applicable) to enable filtering
if hasattr(self.termination_a, 'device'): if hasattr(self.termination_a, 'device'):

View File

@ -1754,10 +1754,13 @@ class CableTraceView(PermissionRequiredMixin, View):
def get(self, request, model, pk): def get(self, request, model, pk):
obj = get_object_or_404(model, pk=pk) obj = get_object_or_404(model, pk=pk)
trace = obj.trace(follow_circuits=True)
total_length = sum([entry[1]._abs_length for entry in trace if entry[1] and entry[1]._abs_length])
return render(request, 'dcim/cable_trace.html', { return render(request, 'dcim/cable_trace.html', {
'obj': obj, 'obj': obj,
'trace': obj.trace(follow_circuits=True), 'trace': trace,
'total_length': total_length,
}) })

View File

@ -10,7 +10,10 @@
<div class="col-md-4 col-md-offset-1 text-center"> <div class="col-md-4 col-md-offset-1 text-center">
<h4>Near End</h4> <h4>Near End</h4>
</div> </div>
<div class="col-md-4 col-md-offset-3 text-center"> <div class="col-md-3 text-center">
{% if total_length %}<h5>Total length: {{ total_length|floatformat:"-2" }} Meters<h5>{% endif %}
</div>
<div class="col-md-4 text-center">
<h4>Far End</h4> <h4>Far End</h4>
</div> </div>
</div> </div>