From 1e4dd102bd05272ace035bce1e4a852bf3797e65 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Tue, 3 Mar 2020 10:35:07 -0500 Subject: [PATCH] Closes #4290: Include device name in tooltip on rack elevations --- docs/release-notes/version-2.7.md | 1 + netbox/dcim/elevations.py | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/docs/release-notes/version-2.7.md b/docs/release-notes/version-2.7.md index a8faf8574..916c94cf5 100644 --- a/docs/release-notes/version-2.7.md +++ b/docs/release-notes/version-2.7.md @@ -7,6 +7,7 @@ * [#3949](https://github.com/netbox-community/netbox/issues/3949) - Revised the installation docs and upgrade script to employ a Python virtual environment * [#4281](https://github.com/netbox-community/netbox/issues/4281) - Allow filtering device component list views by type * [#4284](https://github.com/netbox-community/netbox/issues/4284) - Add MRJ21 port and cable types +* [#4290](https://github.com/netbox-community/netbox/issues/4290) - Include device name in tooltip on rack elevations * [#4305](https://github.com/netbox-community/netbox/issues/4305) - Add 10-inch option for rack width ## Bug Fixes diff --git a/netbox/dcim/elevations.py b/netbox/dcim/elevations.py index a3672f60d..a1af3968c 100644 --- a/netbox/dcim/elevations.py +++ b/netbox/dcim/elevations.py @@ -20,6 +20,16 @@ class RackElevationSVG: self.rack = rack self.include_images = include_images + def _get_device_description(self, device): + return '{} ({}) — {} ({}U) {} {}'.format( + device.name, + device.device_role, + device.device_type.display_name, + device.device_type.u_height, + device.asset_tag or '', + device.serial or '' + ) + @staticmethod def _add_gradient(drawing, id_, color): gradient = drawing.linearGradient( @@ -64,10 +74,7 @@ class RackElevationSVG: fill='black' ) ) - link.set_desc('{} — {} ({}U) {} {}'.format( - device.device_role, device.device_type.display_name, - device.device_type.u_height, device.asset_tag or '', device.serial or '' - )) + link.set_desc(self._get_device_description(device)) link.add(drawing.rect(start, end, style='fill: #{}'.format(color), class_='slot')) hex_color = '#{}'.format(foreground_color(color)) link.add(drawing.text(str(name), insert=text, fill=hex_color)) @@ -81,10 +88,7 @@ class RackElevationSVG: def _draw_device_rear(self, drawing, device, start, end, text): rect = drawing.rect(start, end, class_="slot blocked") - rect.set_desc('{} — {} ({}U) {} {}'.format( - device.device_role, device.device_type.display_name, - device.device_type.u_height, device.asset_tag or '', device.serial or '' - )) + rect.set_desc(self._get_device_description(device)) drawing.add(rect) drawing.add(drawing.text(str(device), insert=text))