Compare commits

...
5 Commits
Author SHA1 Message Date
MrBlakeandClaude Opus 5.5 a6715f1026 fix: single control for technician topology
The technician version needed a scope pill plus a separate granularity
selection; it is now enabled directly by choosing all/per site/per location.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-27 10:27:50 +01:00
MrBlakeandClaude Opus 5.5 daf8bc671b fix: technician topology for all sites, per location and combined
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-27 09:58:58 +01:00
MrBlakeandClaude Opus 5.5 677590f52c feat: technician topology with numbered connections and full port list
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-27 08:59:23 +01:00
MrBlakeandClaude Opus 5.5 27673ee68f fix: location overview includes devices without a location
Devices with only a site (e.g. radio bridge APs) were dropped from the
location overview, so their cables and wireless links disappeared.
They are now grouped in a per-site node "ohne Lokation".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-16 13:18:48 +01:00
MrBlakeandClaude Opus 5.5 174a41e838 feat: wireless links in topology, own top-level navigation menu
Interfaces with a WirelessLink are now traced like cables; wireless-only
connections are drawn blue and dotted with a "Funk" label, also in the
location overviews (counted as "1× Funk"). The plugin gets its own
"Kunden-Export" menu with icon in the main navigation instead of the
Plugins dropdown.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-16 13:14:16 +01:00
10 changed files with 290 additions and 45 deletions

No files matched your search

+6 -4
View File
@@ -39,7 +39,7 @@ All queries respect NetBox permissions (`.restrict(user, "view")`) — a
technician only exports what they are allowed to see.
Open it via the **Customer Docs** button on site, location, tenant and tenant
group pages, or via **Plugins → Customer Documentation**. Output formats:
group pages, or via **Customer Export → Customer Documentation** in the main navigation. Output formats:
**PDF**, **Word** and **HTML preview** (opens in a new tab).
## Compatibility
@@ -182,7 +182,7 @@ sudo systemctl restart netbox netbox-rq
### Branding in NetBox (recommended)
Under **Plugins → Branding profiles**, admins create design profiles directly in NetBox:
Under **Customer Export → Branding Profiles**, admins create design profiles directly in NetBox:
- name, company name, footer and **logo upload** (PNG/JPG)
- colours via colour picker: primary, accent, table header text, labels, zebra stripes
@@ -258,14 +258,16 @@ style of Cisco Packet Tracer:
- The top-to-bottom layout follows the cabling: provider → firewall/router → core → access → end devices, with ordering optimised for as few crossings as possible.
- Lines are routed **orthogonally** on bus bars, coloured per upstream device. Port names sit at the target device; multiple uplinks are drawn thicker and marked "2×".
- **Scope**: *entire network* (one page per site), *location overview* and/or *per rack* (one page per rack). In the rack view, directly connected devices outside the rack appear faded and dashed, with their rack.
- The **location overview** draws one diagram per site with the **locations as nodes** (server room, halls, sub-distributions …). Lines are the physical cables between locations, labelled with count and cable type (e.g. `2× SMF, 4× CAT6a`), so you can follow the cabling from the server room to the last sub-distribution. Locations containing firewalls, routers or core switches are placed at the top; each node shows its parent location and the number of racks and devices.
- The **location overview** draws one diagram per site with the **locations as nodes** (server room, halls, sub-distributions …). Lines are the physical cables between locations, labelled with count and cable type (e.g. `2× SMF, 4× CAT6a`), so you can follow the cabling from the server room to the last sub-distribution. Locations containing firewalls, routers or core switches are placed at the top; each node shows its parent location and the number of racks and devices. Devices without a location (e.g. radio bridges on the roof) are grouped in a node for their site ("without location").
- The **cross-site location overview** puts all locations of all sites in scope into **one diagram**; each node shows its site (and parent location), so you can see how buildings and their locations are connected to each other.
- The **technician version** is meant for third parties (other IT companies, electricians): selectable as *all in one diagram* (across all sites in scope, e.g. for a tenant), *per site* and/or *per location*. In each diagram every link is labelled with connection numbers (`#1`, `#2–4`), followed by a table listing **every single connection** with number, device A / port A, cable (label, type, colour, length), patch panels on the way, and device B / port B.
- Each topology gets its **own landscape page** (PDF and Word) and is scaled as large as possible.
- Provider circuits appear as a cloud, devices of other sites dashed (can be disabled).
- **Wireless links** (NetBox *Wireless links*, e.g. point-to-point radio bridges) appear as blue dotted lines labelled "Wireless", in the network view as well as in the location overviews.
- Selectable labels: management IP, model, ports on links.
- Device names longer than 15 characters are wrapped, preferably at `-`, `_`, `.` or spaces.
**Symbols** (menu **Plugins → Topology symbols**, or the "Topology symbol"
**Symbols** (menu **Customer Export → Topology Symbols**, or the "Topology symbol"
button on device type and device role pages):
1. per **device type**: choose a built-in symbol or **upload a custom icon** (PNG/JPG, ideally transparent)
+1 -1
View File
@@ -6,7 +6,7 @@ class CustomerExportConfig(PluginConfig):
name = "netbox_customer_export"
verbose_name = _("Customer Export")
description = _("Export customer documentation as PDF or Word")
version = "0.18.0"
version = "0.20.2"
author = "Claude"
base_url = "customer-export"
min_version = "4.6.8"
+11
View File
@@ -88,6 +88,17 @@ class ExportForm(forms.Form):
widget=forms.CheckboxSelectMultiple,
label=_("Scope"),
)
topo_tech_per = forms.MultipleChoiceField(
choices=(
("all", _("All in one diagram")),
("site", _("Per site")),
("location", _("Per location")),
),
initial=[],
required=False,
widget=forms.CheckboxSelectMultiple,
label=_("Technician version (numbered connections + port list)"),
)
topo_external = forms.BooleanField(
required=False, initial=True, label=_("Show provider circuits and devices outside the scope")
)
@@ -1534,10 +1534,68 @@ msgstr[0] "%(n)d Rack"
msgstr[1] "%(n)d Racks"
msgid "Cross-site location overview (all locations in one diagram)"
msgstr "Lokationsübersicht standortübergreifend (alle Lokationen in einem Diagramm)"
msgstr ""
"Lokationsübersicht standortübergreifend (alle Lokationen in einem Diagramm)"
msgid "Cross-site location overview"
msgstr "Standortübergreifende Lokationsübersicht"
msgid "All sites"
msgstr "Alle Standorte"
msgid "Wireless"
msgstr "Funk"
msgid "Export"
msgstr "Export"
msgid "Settings"
msgstr "Einstellungen"
msgid "without location"
msgstr "ohne Lokation"
msgid "Technician version (numbered connections + port list)"
msgstr "Techniker-Version (nummerierte Verbindungen + Portliste)"
msgid "Technician version"
msgstr "Techniker-Version"
msgid "Connections – %(name)s"
msgstr "Verbindungen – %(name)s"
msgid "No."
msgstr "Nr."
msgid "Device A"
msgstr "Gerät A"
msgid "Port A"
msgstr "Port A"
msgid "Device B"
msgstr "Gerät B"
msgid "Port B"
msgstr "Port B"
msgid "Via (patch panel)"
msgstr "Über (Patchpanel)"
msgid "Circuit"
msgstr "Leitung"
msgid "All in one diagram"
msgstr "Alles in einem Diagramm"
msgid "Per site"
msgstr "Je Standort"
msgid "Per location"
msgstr "Je Lokation"
msgid "Location %(name)s (%(site)s)"
msgstr "Lokation %(name)s (%(site)s)"
msgid "For third parties (other IT companies, electricians): each connection is numbered in the diagram and listed in a table with exact ports, cable and patch panels. Nothing selected = no technician version."
msgstr "Für Dritte (andere IT-Firmen, Elektriker): Jede Verbindung wird im Diagramm nummeriert und in einer Tabelle mit genauen Ports, Kabel und Patchpanels aufgeführt. Nichts gewählt = keine Techniker-Version."
+12 -2
View File
@@ -1,7 +1,7 @@
from django.utils.translation import gettext_lazy as _
from netbox.plugins import PluginMenuButton, PluginMenuItem
from netbox.plugins import PluginMenu, PluginMenuButton, PluginMenuItem
menu_items = (
_items = (
PluginMenuItem(
link="plugins:netbox_customer_export:select",
link_text=_("Customer Documentation"),
@@ -34,3 +34,13 @@ menu_items = (
),
),
)
# Eigener Eintrag im obersten Navigationsmenü statt unter „Plugins“
menu = PluginMenu(
label=_("Customer Export"),
groups=(
(_("Export"), _items[:1]),
(_("Settings"), _items[1:]),
),
icon_class="mdi mdi-file-document-multiple-outline",
)
+24 -3
View File
@@ -610,7 +610,8 @@ def topology(scope, opts):
from .topology import build_graphs, build_location_graphs, render_png
title = H(1, _("Network topology"))
scopes = opts.get("topo_scope") or ["site"]
# Ohne Auswahl die Standortansicht – außer es ist nur die Techniker-Version gewählt
scopes = opts.get("topo_scope") or ([] if opts.get("topo_tech_per") else ["site"])
ports = "ports" in (opts.get("topo_details") or [])
pages = [] # (Überschriften, Graph) – je eine Querformat-Seite
if "site" in scopes:
@@ -624,10 +625,30 @@ def topology(scope, opts):
racks = build_graphs(scope, opts, per="rack")
# Rack-Seiten unter einer gemeinsamen Zwischenüberschrift, Racks selbst eine Ebene tiefer (kürzeres Inhaltsverzeichnis)
pages += [(([H(2, _("Topology per rack"))] if i == 0 else []) + [H(3, g.title)], g) for i, g in enumerate(racks)]
if not pages:
tech = [] # Techniker-Ansicht: nummerierte Verbindungen + vollständige Portliste je Standort
tech_per = opts.get("topo_tech_per") or []
if tech_per:
from .topology import number_connections
graphs = []
for per in ("all", "site", "location"):
if per in tech_per:
graphs += build_graphs(scope, opts, per=per)
for i, g in enumerate(graphs):
rows = number_connections(g)
head = ([H(2, _("Technician version"))] if i == 0 else []) + [H(3, g.title)]
tech.append((head, g, rows))
if not pages and not tech:
return _empty(opts, [title], _("No cabled devices found."))
# Die Abschnittsüberschrift steht mit auf der ersten Seite
return [
blocks = [
LANDSCAPE(([title] if i == 0 else []) + headings, render_png(g, show_ports=ports))
for i, (headings, g) in enumerate(pages)
]
headers = [_("No."), _("Device A"), _("Port A"), _("Cable"), _("Via (patch panel)"), _("Device B"), _("Port B")]
for head, g, rows in tech:
if not blocks:
head = [title] + head
blocks.append(LANDSCAPE(head, render_png(g)))
blocks += [H(4, _("Connections – %(name)s") % {"name": g.title}), T(headers, rows)]
return blocks
@@ -177,6 +177,9 @@
<div class="ce-label mt-0">{{ form.topo_scope.label }}</div>
{% include 'netbox_customer_export/_pills.html' with field=form.topo_scope %}
<div class="form-text mb-2">{% trans "“Location overview” shows all locations of a site and the cables between them, from the server room to the last sub-distribution. “Cross-site” combines all sites in one diagram to show how buildings and their locations are connected. “Per rack” shows each rack separately. Connected devices outside appear dashed." %}</div>
<div class="ce-label">{{ form.topo_tech_per.label }}</div>
{% include 'netbox_customer_export/_pills.html' with field=form.topo_tech_per %}
<div class="form-text mb-2">{% trans "For third parties (other IT companies, electricians): each connection is numbered in the diagram and listed in a table with exact ports, cable and patch panels. Nothing selected = no technician version." %}</div>
<div class="ce-label">{{ form.topo_details.label }}</div>
{% include 'netbox_customer_export/_pills.html' with field=form.topo_details %}
<div class="ce-label">{% trans "More" %}</div>
+173 -33
View File
@@ -32,6 +32,9 @@ class Edge:
b: str
labels: list = field(default_factory=list)
summary: str = "" # feste Beschriftung statt Port-Namen (z.B. Lokationsübersicht)
wireless: bool = False # nur Funkstrecken (WirelessLink) – blau gepunktet
conns: list = field(default_factory=list) # Einzelverbindungen (Techniker-Ansicht), aus Sicht von a
numbers: list = field(default_factory=list) # laufende Nummern der Einzelverbindungen (Techniker-Ansicht)
@dataclass
@@ -82,7 +85,7 @@ def _device_sub(device, opts):
def build_graphs(scope, opts, per="site"):
"""Ein Graph je Standort (per="site") oder je Rack (per="rack").
"""Ein Graph je Standort (per="site"), Lokation (per="location"), Rack (per="rack") oder einer für alles (per="all").
Verbundene Geräte außerhalb der Gruppe (anderer Standort/anderes Rack) und Provider-Leitungen erscheinen
als externe, gestrichelte Knoten – so sieht man auch in der Rack-Ansicht, wohin die Uplinks gehen.
@@ -90,11 +93,16 @@ def build_graphs(scope, opts, per="site"):
cache = getattr(scope, "_topology_cache", None)
if cache is None:
cache = scope._topology_cache = _collect(scope, opts)
by_pk, drawn, links, external = cache
by_pk, drawn, links, external, wireless, conns = cache
groups = OrderedDict()
for pk in drawn:
d = by_pk[pk]
if per == "all":
key = "all"
elif per == "location":
key = d.location or d.site
else:
key = d.site if per == "site" else d.rack
if key is not None:
groups.setdefault(key, []).append(pk)
@@ -107,6 +115,8 @@ def build_graphs(scope, opts, per="site"):
"""Untertitel eines externen Geräts: wo es steht."""
if per == "rack":
return [_("Rack %(name)s") % {"name": d.rack} if d.rack else str(d.site)]
if per == "location" and d.location:
return [f"{d.site} / {d.location}"]
return [str(d.site)]
graphs = []
@@ -130,14 +140,18 @@ def build_graphs(scope, opts, per="site"):
kind, icon = drawn[d.pk]
other = Node(nid, d.name or str(d), kind, icon, context(d), external=True)
nodes[nid] = Node(**{**other.__dict__})
edges.append(Edge(a, b, labels))
edges.append(Edge(a, b, labels, wireless=(a, b) in wireless, conns=conns.get((a, b), [])))
if not opts.get("topo_isolated"):
linked = {n for e in edges for n in (e.a, e.b)}
nodes = OrderedDict((k, v) for k, v in nodes.items() if k in linked)
if nodes:
_layout(nodes, edges)
if per == "site":
if per == "all":
title = _("All sites")
elif per == "site" or (per == "location" and not hasattr(group, "site")):
title = _("Site %(name)s") % {"name": group}
elif per == "location":
title = _("Location %(name)s (%(site)s)") % {"name": group, "site": group.site}
else:
where = " / ".join(str(x) for x in (group.site, group.location) if x)
title = _("Rack %(name)s (%(where)s)") % {"name": group.name, "where": where}
@@ -148,6 +162,7 @@ def build_graphs(scope, opts, per="site"):
def _collect(scope, opts):
"""Geräte, Symbole und Verbindungen (Kabelpfade) des Scopes einmalig einlesen."""
from dcim.models import Interface
from django.db.models import Q
resolver = SymbolResolver()
devices = list(
@@ -162,11 +177,13 @@ def _collect(scope, opts):
drawn[d.pk] = (kind, icon)
by_pk = {d.pk: d for d in devices}
# Verbindungen: vollständige Kabelpfade (auch über Patchpanels) zwischen Interfaces
# Verbindungen: vollständige Kabelpfade (auch über Patchpanels) und Funkstrecken zwischen Interfaces
links = defaultdict(list) # (a, b) -> ["Gi1/0/1 – eth0", …]
kinds = defaultdict(set) # (a, b) -> {"cable", "wireless"}
conns = defaultdict(list) # (a, b) -> [Einzelverbindung als dict], für die Techniker-Ansicht
external = {} # node_id -> Node-Vorlage
ifaces = scope.restrict(
Interface.objects.filter(device_id__in=list(drawn), cable__isnull=False)
Interface.objects.filter(Q(cable__isnull=False) | Q(wireless_link__isnull=False), device_id__in=list(drawn))
).select_related("device")
for iface in ifaces:
try:
@@ -207,8 +224,96 @@ def _collect(scope, opts):
label = " – ".join(reversed(label.split(" – ")))
if label not in links[key]:
links[key].append(label)
peer_name = label.split(" – ", 1)[1] if model == "interface" else ""
c = _connection(iface, ep, peer_name)
if key[0] != a:
c = _flip(c)
conns[key].append(c)
kinds[key].add("cable" if iface.cable_id else "wireless")
return by_pk, drawn, links, external
wireless = {k for k, v in kinds.items() if v == {"wireless"}}
return by_pk, drawn, links, external, wireless, conns
def _connection(iface, ep, peer_port):
"""Eine Port-zu-Port-Verbindung mit Kabeldaten und Zwischenstationen (Patchpanels)."""
cable = iface.cable
model = ep._meta.model_name
if model == "interface":
peer = ep.device.name or str(ep.device)
elif model == "circuittermination" and getattr(ep, "circuit", None):
peer = f"{ep.circuit.provider} {ep.circuit.cid}"
peer_port = _("Circuit")
else:
peer = str(ep)
cable_parts = []
if cable is not None:
cable_parts.append(cable.label or f"#{cable.pk}")
if cable.type:
cable_parts.append(cable.get_type_display())
if cable.color:
cable_parts.append(cable.get_color_display() if hasattr(cable, "get_color_display") else cable.color)
if cable.length:
from .sections import num
cable_parts.append(f"{num(cable.length)} {cable.get_length_unit_display() if cable.length_unit else ''}".strip())
elif iface.wireless_link_id:
wl = iface.wireless_link
cable_parts.append(_("Wireless") + (f" {wl.ssid}" if getattr(wl, "ssid", "") else ""))
via = []
try:
for _near, _cables, far in iface.trace():
for obj in far or []:
if obj._meta.model_name in ("frontport", "rearport"):
via.append(f"{obj.device} {obj.name}")
except Exception: # noqa: BLE001 – Pfad nicht verfolgbar
via = []
return {
"a_dev": iface.device.name or str(iface.device), "a_port": iface.name,
"b_dev": peer, "b_port": peer_port, "cable": ", ".join(str(x) for x in cable_parts), "via": via,
}
def _flip(c):
return {**c, "a_dev": c["b_dev"], "a_port": c["b_port"], "b_dev": c["a_dev"], "b_port": c["a_port"], "via": list(reversed(c["via"]))}
def number_connections(graph):
"""Techniker-Ansicht: alle Einzelverbindungen durchnummerieren (von oben nach unten, links nach rechts).
Liefert die Tabellenzeilen; jede Kante merkt sich ihre Nummern für die Beschriftung im Diagramm.
"""
nodes = graph.nodes
def pos(e):
a, b = nodes[e.a], nodes[e.b]
top, low = sorted(((a.row, a.x), (b.row, b.x)))
return top, low
rows, n = [], 0
for e in sorted(graph.edges, key=pos):
a, b = nodes[e.a], nodes[e.b]
flip = (a.row, a.x) > (b.row, b.x)
conns = e.conns or [{"a_dev": a.label, "a_port": "", "b_dev": b.label, "b_port": "", "cable": "", "via": []}]
e.numbers = []
for c in conns:
c = _flip(c) if flip else c
n += 1
e.numbers.append(n)
rows.append([n, c["a_dev"], c["a_port"], c["cable"], " → ".join(c["via"]), c["b_dev"], c["b_port"]])
return rows
def _number_text(numbers):
"""[1, 2, 3, 5] -> „1–3, 5“."""
parts, start = [], None
for i, n in enumerate(numbers):
if start is None:
start = n
if i + 1 == len(numbers) or numbers[i + 1] != n + 1:
parts.append(str(start) if start == n else f"{start}–{n}")
start = None
return ", ".join(parts)
def build_location_graphs(scope, opts, combined=False):
@@ -222,45 +327,57 @@ def build_location_graphs(scope, opts, combined=False):
Firewall/Router/Core stehen oben, die Ebenen darunter folgen der Verkabelung.
"""
from dcim.models import FrontPort, Interface, RearPort
from django.db.models import Q
resolver = SymbolResolver()
devices = list(
scope.devices().filter(location__isnull=False)
scope.devices()
.select_related("role", "device_type__manufacturer", "site", "location__parent", "rack")
.order_by("site__name", "location__name")
)
if not devices:
return []
by_pk = {d.pk: d for d in devices}
loc_of = {d.pk: d.location for d in devices}
def node_of(d):
"""Lokation des Geräts – Geräte ohne Lokation (z.B. Richtfunk-APs am Dach) hängen am Standort selbst."""
return f"l{d.location_id}" if d.location_id else f"s{d.site_id}"
nid_of = {d.pk: node_of(d) for d in devices}
# Ebene je Lokation = „höchstes“ Gerät darin (Firewall/Core oben, reine Verteiler darunter)
tier, racks, count = {}, defaultdict(set), defaultdict(int)
for d in devices:
kind, _icon = resolver.resolve(d)
t = KINDS.get(kind, ("", 3))[1] if kind else 3
tier[d.location_id] = min(tier.get(d.location_id, 9), t)
count[d.location_id] += 1
nid = nid_of[d.pk]
tier[nid] = min(tier.get(nid, 9), t)
count[nid] += 1
if d.rack_id:
racks[d.location_id].add(d.rack_id)
racks[nid].add(d.rack_id)
cables = {} # cable.pk -> (Knoten a, Knoten b, Kabel)
cables = {} # ("c"|"w", pk) -> (Knoten a, Knoten b, Kabel oder WirelessLink)
outside = {} # node_id -> Node (andere Standorte / Provider)
for model in (Interface, FrontPort, RearPort):
ports = scope.restrict(model.objects.filter(device_id__in=list(by_pk), cable__isnull=False)).select_related("cable")
cond = Q(cable__isnull=False)
if model is Interface:
cond |= Q(wireless_link__isnull=False)
ports = scope.restrict(model.objects.filter(cond, device_id__in=list(by_pk))).select_related("cable")
for port in ports:
if port.cable_id in cables:
link = port.cable if port.cable_id else port.wireless_link
link_key = ("c", port.cable_id) if port.cable_id else ("w", port.wireless_link_id)
if link_key in cables:
continue
try:
peers = port.link_peers or []
except Exception: # noqa: BLE001
continue
a = f"l{loc_of[port.device_id].pk}"
a = nid_of[port.device_id]
for peer in peers:
peer_dev = getattr(peer, "device", None)
if peer_dev is not None:
if peer_dev.pk in by_pk:
b = f"l{loc_of[peer_dev.pk].pk}"
b = nid_of[peer_dev.pk]
elif not opts.get("topo_external"):
continue
else:
@@ -277,7 +394,7 @@ def build_location_graphs(scope, opts, combined=False):
else:
continue
if a != b:
cables[port.cable_id] = (a, b, port.cable)
cables[link_key] = (a, b, link)
break
links = defaultdict(list)
@@ -285,24 +402,31 @@ def build_location_graphs(scope, opts, combined=False):
links[tuple(sorted((a, b)))].append(cable)
sites = OrderedDict()
all_locs = {}
all_locs = {} # node_id -> (Name, Standort)
for d in devices:
sites.setdefault(None if combined else d.site, OrderedDict())[d.location_id] = d.location
all_locs[f"l{d.location_id}"] = d.location
nid = nid_of[d.pk]
sites.setdefault(None if combined else d.site, OrderedDict())[nid] = d
all_locs[nid] = (d.location.name if d.location_id else str(d.site), d.site)
graphs = []
for site, locations in sites.items():
nodes = OrderedDict()
for loc in locations.values():
for nid, d in locations.items():
loc = d.location
if loc is not None:
name = loc.name
where = [str(loc.site)] if combined else []
if loc.parent_id:
where.append(str(loc.parent))
else:
name = str(d.site)
where = [_("without location")]
sub = [" / ".join(where)] if where else []
n_racks, n_dev = len(racks[loc.pk]), count[loc.pk]
n_racks, n_dev = len(racks[nid]), count[nid]
parts = [ngettext("%(n)d rack", "%(n)d racks", n_racks) % {"n": n_racks}] if n_racks else []
parts.append(ngettext("%(n)d device", "%(n)d devices", n_dev) % {"n": n_dev})
sub.append(" · ".join(parts))
nodes[f"l{loc.pk}"] = Node(f"l{loc.pk}", loc.name, "location", builtin_icon("location"), sub, tier=tier[loc.pk])
nodes[nid] = Node(nid, name, "location", builtin_icon("location"), sub, tier=tier[nid])
members = set(nodes)
edges = []
for (a, b), lst in links.items():
@@ -313,10 +437,13 @@ def build_location_graphs(scope, opts, combined=False):
continue
tpl = outside.get(nid)
if tpl is None: # Lokation im Scope, aber an einem anderen Standort
loc = all_locs[nid]
tpl = Node(nid, loc.name, "location", builtin_icon("location"), [str(loc.site)], external=True)
name, loc_site = all_locs[nid]
tpl = Node(nid, name, "location", builtin_icon("location"), [str(loc_site)], external=True)
nodes[nid] = Node(**{**tpl.__dict__})
edges.append(Edge(a, b, [str(c) for c in lst], summary=_cable_summary(lst)))
edges.append(Edge(
a, b, [str(c) for c in lst], summary=_cable_summary(lst),
wireless=all(c._meta.model_name == "wirelesslink" for c in lst),
))
if not opts.get("topo_isolated"):
linked = {n for e in edges for n in (e.a, e.b)}
nodes = OrderedDict((k, v) for k, v in nodes.items() if k in linked)
@@ -328,9 +455,12 @@ def build_location_graphs(scope, opts, combined=False):
def _cable_summary(cables):
"""„2× SMF, 4× CAT6a“ – Kabel ohne Typ zählen als „Kabel“."""
"""„2× SMF, 4× CAT6a, 1× Funk“ – Kabel ohne Typ zählen als „Kabel“, Funkstrecken als „Funk“."""
types = defaultdict(int)
for c in cables:
if c._meta.model_name == "wirelesslink":
types[_("Wireless")] += 1
else:
types[c.get_type_display() if c.type else _("Cable")] += 1
return ", ".join(f"{n}× {t}" for t, n in sorted(types.items(), key=lambda x: -x[1]))
@@ -430,12 +560,18 @@ def _oriented(graph, e):
def _edge_text(graph, e, show_ports):
if e.numbers:
return "#" + _number_text(e.numbers)
if e.summary:
return e.summary
if show_ports:
labels = _oriented(graph, e)
return labels[0] + (f" (+{len(labels) - 1})" if len(labels) > 1 else "")
return f"{len(e.labels)}×" if len(e.labels) > 1 else None
text = labels[0] + (f" (+{len(labels) - 1})" if len(labels) > 1 else "")
return f"{_('Wireless')}: {text}" if e.wireless else text
count = f"{len(e.labels)}×" if len(e.labels) > 1 else ""
if e.wireless:
return f"{count} {_('Wireless')}".strip()
return count or None
# --- PNG ----------------------------------------------------------------------
@@ -445,6 +581,7 @@ PALETTE = [
(23, 150, 170), (140, 86, 75), (188, 150, 20), (200, 80, 160), (90, 90, 90),
]
EXTERNAL = (160, 160, 160)
WIRELESS = (30, 136, 229) # Funkstrecken: blau, gepunktet
def _font(size, bold=False):
@@ -587,7 +724,8 @@ def render_png(graph, show_ports=False, scale=2):
line([(min(xs), ly), (max(xs), ly)], col, dashed=u.external)
for c, e, ex, stack_pos in entries:
dashed = u.external or c.external
line([(ex, ly), (ex, c.y - 2)], EXTERNAL if dashed else col, w=3 if len(e.labels) > 1 else 2, dashed=dashed)
drop_col = WIRELESS if e.wireless else EXTERNAL if dashed else col
line([(ex, ly), (ex, c.y - 2)], drop_col, w=3 if len(e.labels) > 1 else 2, dashed=dashed or e.wireless)
if min(xs) < ex < max(xs): # Abzweig auf der Schiene markieren
d.ellipse([(ex - 2.5) * S, (ly - 2.5) * S, (ex + 2.5) * S, (ly + 2.5) * S], fill=col)
text = _edge_text(graph, e, show_ports)
@@ -600,7 +738,8 @@ def render_png(graph, show_ports=False, scale=2):
a, b = nodes[e.a], nodes[e.b]
ly = gap["top"] + gap["lane_of"][("s", i)] * LANE
dashed = a.external or b.external
line([(a.x, a.y - 2), (a.x, ly), (b.x, ly), (b.x, b.y - 2)], EXTERNAL if dashed else (70, 70, 70), dashed=dashed)
col = WIRELESS if e.wireless else EXTERNAL if dashed else (70, 70, 70)
line([(a.x, a.y - 2), (a.x, ly), (b.x, ly), (b.x, b.y - 2)], col, dashed=dashed or e.wireless)
text = _edge_text(graph, e, show_ports)
if text:
labels.append((text, (a.x + b.x) / 2, ly, "mm"))
@@ -612,7 +751,8 @@ def render_png(graph, show_ports=False, scale=2):
left, right = (a, b) if a.x < b.x else (b, a)
line(
[(left.x + ICON / 2 + 4, cy), (right.x - ICON / 2 - 4, cy)],
EXTERNAL if dashed else (70, 70, 70), w=3 if len(e.labels) > 1 else 2, dashed=dashed,
WIRELESS if e.wireless else EXTERNAL if dashed else (70, 70, 70),
w=3 if len(e.labels) > 1 else 2, dashed=dashed or e.wireless,
)
text = _edge_text(graph, e, show_ports)
if text:
+1 -1
View File
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "netbox-customer-export"
version = "0.18.0"
version = "0.20.2"
description = "NetBox plugin: customer documentation (PDF/Word) for sites, locations, tenants and tenant groups"
readme = "README.md"
requires-python = ">=3.10"