Files
NetBox-Customer-Export/netbox_customer_export/rack_svg.py
T
MrBlakeandClaude Opus 5.5 1b9970b5dd fix: show rack elevation errors in the exported document
Rack SVG failures were only logged, leaving racks silently without an
image. The error is now written into the document next to the rack so
the cause (e.g. missing rack_elevation.css in STATIC_ROOT) is visible.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-23 13:07:45 +02:00

29 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Rack-Ansichten offline (ohne HTTP-Aufruf der API) als SVG erzeugen."""
import logging
from django.utils.module_loading import import_string
from netbox.plugins import get_plugin_config
logger = logging.getLogger("netbox_customer_export")
def render_rack_svg(rack, face, user):
"""Gibt (svg, fehler) zurück – genau einer der beiden Werte ist None.
Ist ``rack_svg_renderer`` gesetzt (z.B. der Offline-Renderer aus Netbox-Utilities, der mehrere
Geräte pro HE korrekt darstellt), wird dieser aufgerufen: ``fn(rack=..., face=..., user=...)``.
Andernfalls wird NetBox' eigener RackElevationSVG direkt in-process genutzt.
"""
try:
renderer = get_plugin_config("netbox_customer_export", "rack_svg_renderer")
if renderer:
svg = import_string(renderer)(rack=rack, face=face, user=user)
else:
from dcim.svg import RackElevationSVG
svg = RackElevationSVG(rack, 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)
return None, f"{type(e).__name__}: {e}"