Add option to show cable labels (#720)
This commit is contained in:
@@ -50,4 +50,7 @@ class PowerFeedCoordinateSerializer(NetBoxModelSerializer):
|
|||||||
class IndividualOptionsSerializer(NetBoxModelSerializer):
|
class IndividualOptionsSerializer(NetBoxModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = IndividualOptions
|
model = IndividualOptions
|
||||||
fields = ("ignore_cable_type", "save_coords", "show_unconnected", "show_cables", "show_logical_connections", "show_single_cable_logical_conns", "show_neighbors", "show_circuit", "show_power", "show_wireless", "group_sites", "group_locations", "group_racks", "group_virtualchassis", "draw_default_layout", "straight_cables", "draw_termination_labels", "grid_size", "node_label_items")
|
fields = ("ignore_cable_type", "save_coords", "show_unconnected", "show_cables", "show_logical_connections",
|
||||||
|
"show_single_cable_logical_conns", "show_neighbors", "show_circuit", "show_power", "show_wireless", "group_sites",
|
||||||
|
"group_locations", "group_racks", "group_virtualchassis", "draw_default_layout", "straight_cables",
|
||||||
|
"draw_termination_labels", "draw_cable_labels", "grid_size", "node_label_items")
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ class ExportTopoToXML(BaseViewSet, ViewSet):
|
|||||||
|
|
||||||
if request.GET:
|
if request.GET:
|
||||||
|
|
||||||
filter_id, ignore_cable_type, save_coords, show_unconnected, show_power, show_circuit, show_logical_connections, show_single_cable_logical_conns, show_cables, show_wireless, group_sites, group_locations, group_racks, group_virtualchassis, group, show_neighbors, straight_cables, draw_termination_labels, grid_size, node_label_items = get_query_settings(request)
|
filter_id, ignore_cable_type, save_coords, show_unconnected, show_power, show_circuit, show_logical_connections, show_single_cable_logical_conns, show_cables, show_wireless, group_sites, group_locations, group_racks, group_virtualchassis, group, show_neighbors, straight_cables, draw_termination_labels, draw_cable_labels, grid_size, node_label_items = get_query_settings(request)
|
||||||
|
|
||||||
# Read options from saved filters as NetBox does not handle custom plugin filters
|
# Read options from saved filters as NetBox does not handle custom plugin filters
|
||||||
if "filter_id" in request.GET and request.GET["filter_id"] != '':
|
if "filter_id" in request.GET and request.GET["filter_id"] != '':
|
||||||
@@ -138,6 +138,7 @@ class ExportTopoToXML(BaseViewSet, ViewSet):
|
|||||||
if show_neighbors == False and 'show_neighbors' in saved_filter_params: show_neighbors = saved_filter_params['show_neighbors']
|
if show_neighbors == False and 'show_neighbors' in saved_filter_params: show_neighbors = saved_filter_params['show_neighbors']
|
||||||
if straight_cables == False and 'straight_cables' in saved_filter_params: straight_cables = saved_filter_params['straight_cables']
|
if straight_cables == False and 'straight_cables' in saved_filter_params: straight_cables = saved_filter_params['straight_cables']
|
||||||
if draw_termination_labels == False and 'draw_termination_labels' in saved_filter_params: draw_termination_labels = saved_filter_params['draw_termination_labels']
|
if draw_termination_labels == False and 'draw_termination_labels' in saved_filter_params: draw_termination_labels = saved_filter_params['draw_termination_labels']
|
||||||
|
if draw_cable_labels == False and 'draw_cable_labels' in saved_filter_params: draw_cable_labels = saved_filter_params['draw_cable_labels']
|
||||||
if grid_size == 0 and 'grid_size' in saved_filter_params: grid_size = saved_filter_params['grid_size']
|
if grid_size == 0 and 'grid_size' in saved_filter_params: grid_size = saved_filter_params['grid_size']
|
||||||
if node_label_items == () and 'node_label_items' in saved_filter_params: node_label_items = saved_filter_params['node_label_items']
|
if node_label_items == () and 'node_label_items' in saved_filter_params: node_label_items = saved_filter_params['node_label_items']
|
||||||
except SavedFilter.DoesNotExist: # filter_id not found
|
except SavedFilter.DoesNotExist: # filter_id not found
|
||||||
@@ -172,6 +173,7 @@ class ExportTopoToXML(BaseViewSet, ViewSet):
|
|||||||
group_id=group_id,
|
group_id=group_id,
|
||||||
straight_cables=straight_cables,
|
straight_cables=straight_cables,
|
||||||
draw_termination_labels=draw_termination_labels,
|
draw_termination_labels=draw_termination_labels,
|
||||||
|
draw_cable_labels=draw_cable_labels,
|
||||||
grid_size=grid_size,
|
grid_size=grid_size,
|
||||||
node_label_items=node_label_items,
|
node_label_items=node_label_items,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ class DeviceFilterForm(
|
|||||||
FieldSet(
|
FieldSet(
|
||||||
'group', 'ignore_cable_type', 'save_coords', 'show_unconnected', 'show_cables', 'show_wireless',
|
'group', 'ignore_cable_type', 'save_coords', 'show_unconnected', 'show_cables', 'show_wireless',
|
||||||
'show_logical_connections', 'show_single_cable_logical_conns', 'show_neighbors',
|
'show_logical_connections', 'show_single_cable_logical_conns', 'show_neighbors',
|
||||||
'group_sites', 'group_locations', 'group_racks', 'group_virtualchassis', 'straight_cables', 'draw_termination_labels', 'grid_size', 'node_label_items', name=_("Options")
|
'group_sites', 'group_locations', 'group_racks', 'group_virtualchassis', 'straight_cables',
|
||||||
|
'draw_termination_labels', 'draw_cable_labels', 'grid_size', 'node_label_items', name=_("Options")
|
||||||
),
|
),
|
||||||
FieldSet(
|
FieldSet(
|
||||||
'show_circuit', 'show_power', name=_("Additional filter-independent types (non-devices)")
|
'show_circuit', 'show_power', name=_("Additional filter-independent types (non-devices)")
|
||||||
@@ -324,6 +325,12 @@ class DeviceFilterForm(
|
|||||||
choices=BOOLEAN_WITH_BLANK_CHOICES
|
choices=BOOLEAN_WITH_BLANK_CHOICES
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
draw_cable_labels = forms.BooleanField(
|
||||||
|
label=_('Cable Labels'), required=False, initial=False,
|
||||||
|
widget=forms.Select(
|
||||||
|
choices=BOOLEAN_WITH_BLANK_CHOICES
|
||||||
|
)
|
||||||
|
)
|
||||||
grid_size = forms.IntegerField(
|
grid_size = forms.IntegerField(
|
||||||
label=_('Grid Size'),
|
label=_('Grid Size'),
|
||||||
required=False,
|
required=False,
|
||||||
@@ -545,6 +552,7 @@ class IndividualOptionsForm(NetBoxModelForm):
|
|||||||
'draw_default_layout',
|
'draw_default_layout',
|
||||||
'straight_cables',
|
'straight_cables',
|
||||||
'draw_termination_labels',
|
'draw_termination_labels',
|
||||||
|
'draw_cable_labels',
|
||||||
'grid_size',
|
'grid_size',
|
||||||
'node_label_items',
|
'node_label_items',
|
||||||
),
|
),
|
||||||
@@ -686,6 +694,12 @@ class IndividualOptionsForm(NetBoxModelForm):
|
|||||||
help_text=_('Enable this option if you want to draw a label on each '
|
help_text=_('Enable this option if you want to draw a label on each '
|
||||||
'cable end.')
|
'cable end.')
|
||||||
)
|
)
|
||||||
|
draw_cable_labels = forms.BooleanField(
|
||||||
|
label=('Cable Labels'),
|
||||||
|
required=False,
|
||||||
|
initial=False,
|
||||||
|
help_text=_('Enable this option if you want to draw a cable labels.')
|
||||||
|
)
|
||||||
grid_size = forms.IntegerField(
|
grid_size = forms.IntegerField(
|
||||||
label=_('Grid Size'),
|
label=_('Grid Size'),
|
||||||
required=True,
|
required=True,
|
||||||
@@ -727,6 +741,6 @@ class IndividualOptionsForm(NetBoxModelForm):
|
|||||||
'save_coords', 'show_unconnected', 'show_cables', 'show_wireless',
|
'save_coords', 'show_unconnected', 'show_cables', 'show_wireless',
|
||||||
'show_logical_connections', 'show_single_cable_logical_conns', 'show_neighbors',
|
'show_logical_connections', 'show_single_cable_logical_conns', 'show_neighbors',
|
||||||
'group_sites', 'group_locations', 'group_racks', 'group_virtualchassis',
|
'group_sites', 'group_locations', 'group_racks', 'group_virtualchassis',
|
||||||
'draw_default_layout', 'straight_cables', 'draw_termination_labels', 'grid_size', 'node_label_items',
|
'draw_default_layout', 'straight_cables', 'draw_termination_labels', 'draw_cable_labels',
|
||||||
'show_circuit', 'show_power'
|
'grid_size', 'node_label_items', 'show_circuit', 'show_power'
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.2.12 on 2026-03-26 07:39
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('netbox_topology_views', '0012_individualoptions_draw_termination_labels'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='individualoptions',
|
||||||
|
name='draw_cable_labels',
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -408,6 +408,9 @@ class IndividualOptions(NetBoxModel):
|
|||||||
draw_termination_labels = models.BooleanField(
|
draw_termination_labels = models.BooleanField(
|
||||||
default=False
|
default=False
|
||||||
)
|
)
|
||||||
|
draw_cable_labels = models.BooleanField(
|
||||||
|
default=False
|
||||||
|
)
|
||||||
grid_size = models.PositiveSmallIntegerField(
|
grid_size = models.PositiveSmallIntegerField(
|
||||||
default=0
|
default=0
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -201,6 +201,11 @@ def get_query_settings(request):
|
|||||||
if request.GET["draw_termination_labels"] == "True":
|
if request.GET["draw_termination_labels"] == "True":
|
||||||
draw_termination_labels = True
|
draw_termination_labels = True
|
||||||
|
|
||||||
|
draw_cable_labels = False
|
||||||
|
if "draw_cable_labels" in request.GET:
|
||||||
|
if request.GET["draw_cable_labels"] == "True":
|
||||||
|
draw_cable_labels = True
|
||||||
|
|
||||||
grid_size = 0
|
grid_size = 0
|
||||||
if "grid_size" in request.GET:
|
if "grid_size" in request.GET:
|
||||||
grid_size = request.GET.getlist('grid_size')
|
grid_size = request.GET.getlist('grid_size')
|
||||||
@@ -209,7 +214,7 @@ def get_query_settings(request):
|
|||||||
if "node_label_items" in request.GET:
|
if "node_label_items" in request.GET:
|
||||||
node_label_items = request.GET.getlist('node_label_items')
|
node_label_items = request.GET.getlist('node_label_items')
|
||||||
|
|
||||||
return filter_id, ignore_cable_type, save_coords, show_unconnected, show_power, show_circuit, show_logical_connections, show_single_cable_logical_conns, show_cables, show_wireless, group_sites, group_locations, group_racks, group_virtualchassis, group, show_neighbors, straight_cables, draw_termination_labels, grid_size, node_label_items
|
return filter_id, ignore_cable_type, save_coords, show_unconnected, show_power, show_circuit, show_logical_connections, show_single_cable_logical_conns, show_cables, show_wireless, group_sites, group_locations, group_racks, group_virtualchassis, group, show_neighbors, straight_cables, draw_termination_labels, draw_cable_labels, grid_size, node_label_items
|
||||||
|
|
||||||
class LinePattern():
|
class LinePattern():
|
||||||
wireless = [2, 10, 2, 10]
|
wireless = [2, 10, 2, 10]
|
||||||
|
|||||||
@@ -271,6 +271,7 @@ def create_edge(
|
|||||||
termination_b: Dict,
|
termination_b: Dict,
|
||||||
straight_cables: bool,
|
straight_cables: bool,
|
||||||
draw_termination_labels: bool,
|
draw_termination_labels: bool,
|
||||||
|
draw_cable_labels: bool,
|
||||||
circuit: Optional[Dict] = None,
|
circuit: Optional[Dict] = None,
|
||||||
cable: Optional[Cable] = None,
|
cable: Optional[Cable] = None,
|
||||||
wireless: Optional[Dict] = None,
|
wireless: Optional[Dict] = None,
|
||||||
@@ -326,6 +327,8 @@ def create_edge(
|
|||||||
|
|
||||||
if cable is not None and hasattr(cable, "label") and cable.label:
|
if cable is not None and hasattr(cable, "label") and cable.label:
|
||||||
cable_label = "<br>Label: " + cable.label
|
cable_label = "<br>Label: " + cable.label
|
||||||
|
if draw_cable_labels is True:
|
||||||
|
edge["label"] = cable.label
|
||||||
else:
|
else:
|
||||||
cable_label = ""
|
cable_label = ""
|
||||||
|
|
||||||
@@ -390,6 +393,7 @@ def get_topology_data(
|
|||||||
group_id,
|
group_id,
|
||||||
straight_cables: bool,
|
straight_cables: bool,
|
||||||
draw_termination_labels: bool,
|
draw_termination_labels: bool,
|
||||||
|
draw_cable_labels: bool,
|
||||||
grid_size: list,
|
grid_size: list,
|
||||||
node_label_items: list,
|
node_label_items: list,
|
||||||
):
|
):
|
||||||
@@ -489,6 +493,7 @@ def get_topology_data(
|
|||||||
termination_b=termination_b,
|
termination_b=termination_b,
|
||||||
straight_cables=straight_cables,
|
straight_cables=straight_cables,
|
||||||
draw_termination_labels=draw_termination_labels,
|
draw_termination_labels=draw_termination_labels,
|
||||||
|
draw_cable_labels=draw_cable_labels,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -560,6 +565,7 @@ def get_topology_data(
|
|||||||
power=True,
|
power=True,
|
||||||
straight_cables=straight_cables,
|
straight_cables=straight_cables,
|
||||||
draw_termination_labels=draw_termination_labels,
|
draw_termination_labels=draw_termination_labels,
|
||||||
|
draw_cable_labels=draw_cable_labels,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -598,7 +604,7 @@ def get_topology_data(
|
|||||||
edge_ids += 1
|
edge_ids += 1
|
||||||
termination_a = { "termination_name": interface.name, "termination_device_name": interface.device.name, "device_id": interface.device.id }
|
termination_a = { "termination_name": interface.name, "termination_device_name": interface.device.name, "device_id": interface.device.id }
|
||||||
termination_b = { "termination_name": destination.name, "termination_device_name": destination.device.name, "device_id": destination.device.id }
|
termination_b = { "termination_name": destination.name, "termination_device_name": destination.device.name, "device_id": destination.device.id }
|
||||||
edges.append(create_edge(edge_id=edge_ids, termination_a=termination_a, termination_b=termination_b, interface=interface, straight_cables=straight_cables, draw_termination_labels=draw_termination_labels))
|
edges.append(create_edge(edge_id=edge_ids, termination_a=termination_a, termination_b=termination_b, interface=interface, straight_cables=straight_cables, draw_termination_labels=draw_termination_labels, draw_cable_labels=draw_cable_labels))
|
||||||
nodes_devices[interface.device.id] = interface.device
|
nodes_devices[interface.device.id] = interface.device
|
||||||
nodes_devices[destination.device.id] = destination.device
|
nodes_devices[destination.device.id] = destination.device
|
||||||
|
|
||||||
@@ -680,6 +686,7 @@ def get_topology_data(
|
|||||||
termination_b=termination_b,
|
termination_b=termination_b,
|
||||||
straight_cables=straight_cables,
|
straight_cables=straight_cables,
|
||||||
draw_termination_labels=draw_termination_labels,
|
draw_termination_labels=draw_termination_labels,
|
||||||
|
draw_cable_labels=draw_cable_labels,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -721,6 +728,7 @@ def get_topology_data(
|
|||||||
wireless=wireless,
|
wireless=wireless,
|
||||||
straight_cables=straight_cables,
|
straight_cables=straight_cables,
|
||||||
draw_termination_labels=draw_termination_labels,
|
draw_termination_labels=draw_termination_labels,
|
||||||
|
draw_cable_labels=draw_cable_labels,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -775,7 +783,7 @@ class TopologyHomeView(PermissionRequiredMixin, View):
|
|||||||
|
|
||||||
if request.GET:
|
if request.GET:
|
||||||
|
|
||||||
filter_id, ignore_cable_type, save_coords, show_unconnected, show_power, show_circuit, show_logical_connections, show_single_cable_logical_conns, show_cables, show_wireless, group_sites, group_locations, group_racks, group_virtualchassis, group, show_neighbors, straight_cables, draw_termination_labels, grid_size, node_label_items = get_query_settings(request)
|
filter_id, ignore_cable_type, save_coords, show_unconnected, show_power, show_circuit, show_logical_connections, show_single_cable_logical_conns, show_cables, show_wireless, group_sites, group_locations, group_racks, group_virtualchassis, group, show_neighbors, straight_cables, draw_termination_labels, draw_cable_labels, grid_size, node_label_items = get_query_settings(request)
|
||||||
|
|
||||||
filter_required = True
|
filter_required = True
|
||||||
empty_result = False
|
empty_result = False
|
||||||
@@ -802,6 +810,7 @@ class TopologyHomeView(PermissionRequiredMixin, View):
|
|||||||
if show_neighbors == False and 'show_neighbors' in saved_filter_params: show_neighbors = saved_filter_params['show_neighbors']
|
if show_neighbors == False and 'show_neighbors' in saved_filter_params: show_neighbors = saved_filter_params['show_neighbors']
|
||||||
if straight_cables == False and 'straight_cables' in saved_filter_params: straight_cables = saved_filter_params['straight_cables']
|
if straight_cables == False and 'straight_cables' in saved_filter_params: straight_cables = saved_filter_params['straight_cables']
|
||||||
if draw_termination_labels == False and 'draw_termination_labels' in saved_filter_params: draw_termination_labels = saved_filter_params['draw_termination_labels']
|
if draw_termination_labels == False and 'draw_termination_labels' in saved_filter_params: draw_termination_labels = saved_filter_params['draw_termination_labels']
|
||||||
|
if draw_cable_labels == False and 'draw_cable_labels' in saved_filter_params: draw_cable_labels = saved_filter_params['draw_cable_labels']
|
||||||
if grid_size == 0 and 'grid_size' in saved_filter_params: grid_size = saved_filter_params['grid_size']
|
if grid_size == 0 and 'grid_size' in saved_filter_params: grid_size = saved_filter_params['grid_size']
|
||||||
if node_label_items == () and 'node_label_items' in saved_filter_params: node_label_items = saved_filter_params['node_label_items']
|
if node_label_items == () and 'node_label_items' in saved_filter_params: node_label_items = saved_filter_params['node_label_items']
|
||||||
except SavedFilter.DoesNotExist: # filter_id not found
|
except SavedFilter.DoesNotExist: # filter_id not found
|
||||||
@@ -840,6 +849,7 @@ class TopologyHomeView(PermissionRequiredMixin, View):
|
|||||||
group_id=group_id,
|
group_id=group_id,
|
||||||
straight_cables=straight_cables,
|
straight_cables=straight_cables,
|
||||||
draw_termination_labels=draw_termination_labels,
|
draw_termination_labels=draw_termination_labels,
|
||||||
|
draw_cable_labels=draw_cable_labels,
|
||||||
grid_size=grid_size,
|
grid_size=grid_size,
|
||||||
node_label_items=node_label_items,
|
node_label_items=node_label_items,
|
||||||
)
|
)
|
||||||
@@ -874,6 +884,7 @@ class TopologyHomeView(PermissionRequiredMixin, View):
|
|||||||
if individualOptions.group_virtualchassis: q['group_virtualchassis'] = "True"
|
if individualOptions.group_virtualchassis: q['group_virtualchassis'] = "True"
|
||||||
if individualOptions.straight_cables: q['straight_cables'] = "True"
|
if individualOptions.straight_cables: q['straight_cables'] = "True"
|
||||||
if individualOptions.draw_termination_labels: q['draw_termination_labels'] = "True"
|
if individualOptions.draw_termination_labels: q['draw_termination_labels'] = "True"
|
||||||
|
if individualOptions.draw_cable_labels: q['draw_cable_labels'] = "True"
|
||||||
if individualOptions.grid_size: q['grid_size'] = individualOptions.grid_size
|
if individualOptions.grid_size: q['grid_size'] = individualOptions.grid_size
|
||||||
node_label_items = IndividualOptions.objects.get(id=individualOptions.id).node_label_items.translate({ord(i): None for i in '[]\''}).split(', ')
|
node_label_items = IndividualOptions.objects.get(id=individualOptions.id).node_label_items.translate({ord(i): None for i in '[]\''}).split(', ')
|
||||||
if node_label_items == ['']: node_label_items = []
|
if node_label_items == ['']: node_label_items = []
|
||||||
@@ -1228,6 +1239,7 @@ class TopologyIndividualOptionsView(PermissionRequiredMixin, View):
|
|||||||
'draw_default_layout': queryset.draw_default_layout,
|
'draw_default_layout': queryset.draw_default_layout,
|
||||||
'straight_cables': queryset.straight_cables,
|
'straight_cables': queryset.straight_cables,
|
||||||
'draw_termination_labels': queryset.draw_termination_labels,
|
'draw_termination_labels': queryset.draw_termination_labels,
|
||||||
|
'draw_cable_labels': queryset.draw_cable_labels,
|
||||||
'grid_size': queryset.grid_size,
|
'grid_size': queryset.grid_size,
|
||||||
'node_label_items': tuple(queryset.node_label_items.translate({ord(i): None for i in '[]\''}).split(', ')),
|
'node_label_items': tuple(queryset.node_label_items.translate({ord(i): None for i in '[]\''}).split(', ')),
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user