fix: rack elevations missing in all export formats

RackElevationSVG falls back to RACK_ELEVATION_DEFAULT_* config
parameters, which raise AttributeError on the target NetBox version.
Pass the dimensions explicitly instead.

Add a Pillow-based PNG rack renderer (role colors, unit legend,
full-depth devices shown dimmed from the other side). It is used for
Word when cairosvg is unavailable and replaces a failed SVG in all
formats.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-23 13:15:34 +02:00
co-authored by Claude Opus 5.5
parent 8cc861e6af
commit c37626aff1
5 changed files with 159 additions and 13 deletions
+18 -1
View File
@@ -6,6 +6,12 @@ from netbox.plugins import get_plugin_config
logger = logging.getLogger("netbox_customer_export")
# NetBox-Standardwerte der Rack-Ansicht
UNIT_WIDTH = 220
UNIT_HEIGHT = 22
LEGEND_WIDTH = 30
MARGIN_WIDTH = 15
def render_rack_svg(rack, face, user):
"""Gibt (svg, fehler) zurück – genau einer der beiden Werte ist None.
@@ -21,7 +27,18 @@ def render_rack_svg(rack, face, user):
else:
from dcim.svg import RackElevationSVG
svg = RackElevationSVG(rack, user=user, include_images=False, base_url="").render(face)
# Maße explizit übergeben: je nach NetBox-Version fehlen die RACK_ELEVATION_DEFAULT_*-Parameter
# in der Konfiguration, dann bricht der Renderer mit AttributeError ab.
svg = RackElevationSVG(
rack,
unit_width=UNIT_WIDTH,
unit_height=UNIT_HEIGHT,
legend_width=LEGEND_WIDTH,
margin_width=MARGIN_WIDTH,
user=user,
include_images=False,
base_url="",
).render(face)
return (svg.tostring() if hasattr(svg, "tostring") else str(svg)), None
except Exception as e: # noqa: BLE001 – ein defektes Rack soll nicht den ganzen Export abbrechen
logger.exception("Rack-SVG für %s (%s) fehlgeschlagen", rack, face)