feat: switch port PDF in A4 portrait

The export uses A4 portrait: wide port groups are split evenly (a 48-port
switch into 1-24 and 25-48) with larger tiles, the legend has four
columns and the port list has wider columns and a smaller font so that
names, status and type no longer wrap.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
MrBlakeandClaude Opus 5.5 committed 2026-10-30 09:28:56 +01:00
1 parent 8eb075db9f
commit f144f23b31
4 files changed
+13 -13

No files matched your search

+3 -3
View File
@@ -509,7 +509,7 @@ recording and editing use `netbox_utilities.add_devicehardware` and
Devices with a role from `switch_device_roles` get an **Export switch port Devices with a role from `switch_device_roles` get an **Export switch port
usage** button (*Switch-Belegung exportieren*) on the device page. It usage** button (*Switch-Belegung exportieren*) on the device page. It
downloads a PDF (A4 landscape) with: downloads a PDF (A4 portrait) with:
- **Header:** device, site, rack/position, model and date, plus the key - **Header:** device, site, rack/position, model and date, plus the key
figures: physical ports, connected (with percentage), free and disabled. figures: physical ports, connected (with percentage), free and disabled.
@@ -521,8 +521,8 @@ downloads a PDF (A4 landscape) with:
as the same VLAN); connected ports are filled with the full colour and a as the same VLAN); connected ports are filled with the full colour and a
thick border, free ports with a pale version, disabled ports have a dashed thick border, free ports with a pale version, disabled ports have a dashed
border and a small ✕. The text colour is chosen per tile for the best border and a small ✕. The text colour is chosen per tile for the best
contrast (black or white). Tile widths adapt so that a 48-port switch fits contrast (black or white). Wide groups are split evenly, e.g. a 48-port
on one row. switch into ports 1–24 and 25–48.
- **Legend:** every VLAN with its colour and connected/total ports. - **Legend:** every VLAN with its colour and connected/total ports.
- **Port list:** all interfaces (including virtual ones such as LAGs and SVIs) - **Port list:** all interfaces (including virtual ones such as LAGs and SVIs)
with status, VLAN label, peer, description, type and LAG. The peer is the with status, VLAN label, peer, description, type and LAG. The peer is the
+1 -1
View File
@@ -1,6 +1,6 @@
from netbox.plugins import PluginConfig, get_plugin_config from netbox.plugins import PluginConfig, get_plugin_config
__version__ = "0.18.0" __version__ = "0.18.1"
class NetBoxUtilitiesConfig(PluginConfig): class NetBoxUtilitiesConfig(PluginConfig):
+8 -8
View File
@@ -9,7 +9,7 @@ from dataclasses import dataclass, field
from datetime import datetime from datetime import datetime
from reportlab.lib import colors from reportlab.lib import colors
from reportlab.lib.pagesizes import A4, landscape from reportlab.lib.pagesizes import A4
from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet from reportlab.lib.styles import ParagraphStyle, getSampleStyleSheet
from reportlab.lib.units import mm from reportlab.lib.units import mm
from reportlab.platypus import Flowable, KeepTogether, Paragraph, SimpleDocTemplate, Spacer, Table, TableStyle from reportlab.platypus import Flowable, KeepTogether, Paragraph, SimpleDocTemplate, Spacer, Table, TableStyle
@@ -80,12 +80,12 @@ TEXTS = {
}, },
} }
PAGE = landscape(A4) PAGE = A4
MARGIN = 12 * mm MARGIN = 12 * mm
TILE_W = 10.5 * mm TILE_W = 12.5 * mm
TILE_H = 9 * mm TILE_H = 9.5 * mm
TILE_GAP = 1.2 * mm TILE_GAP = 1.2 * mm
OPTICAL_W = 12 * mm OPTICAL_W = 13.5 * mm
FREE_FILL = colors.white FREE_FILL = colors.white
UNLABELLED_FILL = colors.HexColor("#e9ecef") UNLABELLED_FILL = colors.HexColor("#e9ecef")
BORDER_DARK = colors.HexColor("#212529") BORDER_DARK = colors.HexColor("#212529")
@@ -226,7 +226,7 @@ def _styles():
"meta": ParagraphStyle("m", parent=sheet["Normal"], fontSize=8.5, textColor=colors.HexColor("#495057")), "meta": ParagraphStyle("m", parent=sheet["Normal"], fontSize=8.5, textColor=colors.HexColor("#495057")),
"h2": ParagraphStyle("h", parent=sheet["Heading2"], fontSize=11, spaceBefore=3 * mm, spaceAfter=1.5 * mm), "h2": ParagraphStyle("h", parent=sheet["Heading2"], fontSize=11, spaceBefore=3 * mm, spaceAfter=1.5 * mm),
"group": ParagraphStyle("g", parent=sheet["Normal"], fontSize=7.5, textColor=colors.HexColor("#495057")), "group": ParagraphStyle("g", parent=sheet["Normal"], fontSize=7.5, textColor=colors.HexColor("#495057")),
"cell": ParagraphStyle("c", parent=sheet["Normal"], fontSize=7, leading=8.5), "cell": ParagraphStyle("c", parent=sheet["Normal"], fontSize=6.5, leading=7.8),
"figure": ParagraphStyle("f", parent=sheet["Normal"], fontSize=14, leading=16), "figure": ParagraphStyle("f", parent=sheet["Normal"], fontSize=14, leading=16),
"small": ParagraphStyle("s", parent=sheet["Normal"], fontSize=7, textColor=colors.HexColor("#495057")), "small": ParagraphStyle("s", parent=sheet["Normal"], fontSize=7, textColor=colors.HexColor("#495057")),
} }
@@ -279,7 +279,7 @@ def _legend(ports, t, styles):
items.append((fill, f"{label} <font color='#6c757d'>({connected}/{total})</font>")) items.append((fill, f"{label} <font color='#6c757d'>({connected}/{total})</font>"))
if not items: if not items:
return [] return []
per_row = 6 per_row = 4
cells = [] cells = []
style = [("VALIGN", (0, 0), (-1, -1), "MIDDLE"), ("LEFTPADDING", (0, 0), (-1, -1), 1 * mm)] style = [("VALIGN", (0, 0), (-1, -1), "MIDDLE"), ("LEFTPADDING", (0, 0), (-1, -1), 1 * mm)]
for row_index in range(math.ceil(len(items) / per_row)): for row_index in range(math.ceil(len(items) / per_row)):
@@ -334,7 +334,7 @@ def _port_table(ports, t, styles):
if port.state == switch_ports.STATE_DISABLED: if port.state == switch_ports.STATE_DISABLED:
style.append(("TEXTCOLOR", (0, index), (1, index), colors.HexColor("#6c757d"))) style.append(("TEXTCOLOR", (0, index), (1, index), colors.HexColor("#6c757d")))
width = PAGE[0] - 2 * MARGIN width = PAGE[0] - 2 * MARGIN
widths = [w * width for w in (0.13, 0.08, 0.11, 0.25, 0.22, 0.13, 0.08)] widths = [w * width for w in (0.19, 0.09, 0.12, 0.21, 0.17, 0.15, 0.07)]
table = Table(data, colWidths=widths, repeatRows=1) table = Table(data, colWidths=widths, repeatRows=1)
table.setStyle(TableStyle(style)) table.setStyle(TableStyle(style))
return table return table
+1 -1
View File
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project] [project]
name = "netbox-utilities" name = "netbox-utilities"
version = "0.18.0" version = "0.18.1"
description = "Navigation, tenant utilities, connection VLANs, partial-width racks, disks, CPU & RAM, switch port export and bulk operations for NetBox 4.6/4.7" description = "Navigation, tenant utilities, connection VLANs, partial-width racks, disks, CPU & RAM, switch port export and bulk operations for NetBox 4.6/4.7"
readme = "README.md" readme = "README.md"
requires-python = ">=3.12" requires-python = ">=3.12"