feat: honor images-only/labels-only rack view mode in offline SVG export

The rack elevation page's "Bilder und Beschriftungen" dropdown only
toggles CSS visibility client-side after the browser already has the
SVG, so a freshly server-rendered export had no way to know which mode
was selected and always exported everything.

apply_rack_view_mode() replicates that filtering server-side by
removing the .label text elements (images-only) or the .device-image /
.device-image-label elements (labels-only) from the parsed SVG.
RackElevationOfflineSVGView now accepts a ?view= query param, and the
rack detail page panel syncs its download links to the page's own
"select.rack-view" dropdown so the exported file matches what's
currently shown.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-17 15:30:38 +02:00
co-authored by Claude Sonnet 5
parent 20ec9453c2
commit bfc4382403
6 changed files with 92 additions and 7 deletions
+30 -1
View File
@@ -1,6 +1,6 @@
from django.test import SimpleTestCase
from netbox_utilities.svg_export import strip_svg_hyperlinks
from netbox_utilities.svg_export import apply_rack_view_mode, strip_svg_hyperlinks
class StripSvgHyperlinksTest(SimpleTestCase):
@@ -91,3 +91,32 @@ class StripSvgHyperlinksTest(SimpleTestCase):
self.assertIn("<rect", result)
self.assertNotIn("href", result)
class ApplyRackViewModeTest(SimpleTestCase):
SVG = (
'<svg xmlns="http://www.w3.org/2000/svg">'
'<text class="label">USV 8</text>'
'<image class="device-image"/>'
'<text class="device-image-label">USV 8</text>'
"</svg>"
)
def test_images_and_labels_leaves_svg_untouched(self):
self.assertEqual(apply_rack_view_mode(self.SVG, "images-and-labels"), self.SVG)
def test_images_only_removes_label_text(self):
result = apply_rack_view_mode(self.SVG, "images-only")
self.assertNotIn('class="label"', result)
self.assertIn('class="device-image"', result)
self.assertIn('class="device-image-label"', result)
def test_labels_only_removes_device_images(self):
result = apply_rack_view_mode(self.SVG, "labels-only")
self.assertIn('class="label"', result)
self.assertNotIn("device-image", result)
def test_unknown_mode_leaves_svg_untouched(self):
self.assertEqual(apply_rack_view_mode(self.SVG, "bogus"), self.SVG)