feat: export switch port usage as PDF instead of a Ports tab
Switches get an "Export switch port usage" button that downloads an A4 landscape PDF: key figures, a front panel with one colour per VLAN label (full colour = connected, pale = free, dashed with a cross = disabled, text colour chosen for contrast), a VLAN legend and the full port list with peers. The PDF follows the language of the user's NetBox preferences (German or English). The Ports tab with its script and styles is removed. ReportLab becomes a dependency. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
8f2cc22f88
commit
8eb075db9f
13 files changed
+611
-452
No files matched your search
@@ -1,6 +1,7 @@
|
||||
from dcim.models import ModuleBay
|
||||
from django.middleware.csrf import get_token
|
||||
from django.urls import reverse
|
||||
from django.utils import translation
|
||||
from netbox.plugins import PluginTemplateExtension
|
||||
from tenancy.models import Tenant, TenantGroup
|
||||
|
||||
@@ -24,6 +25,7 @@ from .runtime import (
|
||||
hardware_enabled,
|
||||
navigation_customization_enabled,
|
||||
offline_svg_export_enabled,
|
||||
switch_ports_enabled,
|
||||
tenant_filter_enabled,
|
||||
)
|
||||
|
||||
@@ -94,6 +96,20 @@ class DeviceUtilitiesContent(PluginTemplateExtension):
|
||||
models = ["dcim.device"]
|
||||
|
||||
def buttons(self):
|
||||
return self._switch_ports_button() + self._bulk_module_button()
|
||||
|
||||
def _switch_ports_button(self):
|
||||
request, device = self.context["request"], self.context["object"]
|
||||
if not switch_ports_enabled() or not request.user.has_perm("dcim.view_interface"):
|
||||
return ""
|
||||
from . import switch_port_pdf, switch_ports
|
||||
|
||||
if not switch_ports.is_switch(device):
|
||||
return ""
|
||||
texts = switch_port_pdf.TEXTS[switch_port_pdf.language(translation.get_language())]
|
||||
return self.render("netbox_utilities/device_switch_ports_button.html", {"label": texts["button"]})
|
||||
|
||||
def _bulk_module_button(self):
|
||||
request = self.context["request"]
|
||||
device = self.context["object"]
|
||||
if not request.user.has_perm("dcim.add_module"):
|
||||
|
||||
Reference in new issue
Block a user