From 5a67bdca72823347cc24d2450126caba27d0762b Mon Sep 17 00:00:00 2001 From: Daniel Bremer Date: Thu, 2 May 2024 11:08:31 +0200 Subject: [PATCH 1/9] allow disabling smooth cables and render them as straight lines instead --- netbox_topology_views/api/serializers.py | 2 +- netbox_topology_views/api/views.py | 1 + netbox_topology_views/forms.py | 11 ++++++++++- .../migrations/008_disable_smooth_cables.py | 18 ++++++++++++++++++ netbox_topology_views/models.py | 3 +++ netbox_topology_views/views.py | 13 ++++++++++++- 6 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 netbox_topology_views/migrations/008_disable_smooth_cables.py diff --git a/netbox_topology_views/api/serializers.py b/netbox_topology_views/api/serializers.py index f6e272f..800886e 100644 --- a/netbox_topology_views/api/serializers.py +++ b/netbox_topology_views/api/serializers.py @@ -50,4 +50,4 @@ class Meta: class IndividualOptionsSerializer(NetBoxModelSerializer): class Meta: 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", "draw_default_layout") + 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", "draw_default_layout", "disable_smooth_cables") diff --git a/netbox_topology_views/api/views.py b/netbox_topology_views/api/views.py index 6741dd8..0a22ae1 100644 --- a/netbox_topology_views/api/views.py +++ b/netbox_topology_views/api/views.py @@ -153,6 +153,7 @@ def list(self, request): group_locations=group_locations, group_racks=group_racks, group_id=group_id, + disable_smooth_cables=individualOptions.disable_smooth_cables, ) xml_data = export_data_to_xml(topo_data).decode('utf-8') diff --git a/netbox_topology_views/forms.py b/netbox_topology_views/forms.py index cfda465..1a7ac1d 100644 --- a/netbox_topology_views/forms.py +++ b/netbox_topology_views/forms.py @@ -461,6 +461,7 @@ class IndividualOptionsForm(NetBoxModelForm): 'group_locations', 'group_racks', 'draw_default_layout', + 'disable_smooth_cables', ), ), ) @@ -589,6 +590,13 @@ class IndividualOptionsForm(NetBoxModelForm): help_text=_('Enable this option if you want to draw the topology on ' 'the initial load (when you go to the topology plugin page).') ) + disable_smooth_cables = forms.BooleanField( + label=('Disable Smooth Cables'), + required=False, + initial=False, + help_text=_('Enable this option if you want to draw cables as straight lines ' + 'instead of curves.') + ) class Meta: model = IndividualOptions @@ -596,5 +604,6 @@ class Meta: 'user_id', 'ignore_cable_type', 'preselected_device_roles', 'preselected_tags', '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', 'draw_default_layout' + 'show_wireless', 'group_sites', 'group_locations', 'group_racks', 'draw_default_layout', + 'disable_smooth_cables' ] diff --git a/netbox_topology_views/migrations/008_disable_smooth_cables.py b/netbox_topology_views/migrations/008_disable_smooth_cables.py new file mode 100644 index 0000000..493b202 --- /dev/null +++ b/netbox_topology_views/migrations/008_disable_smooth_cables.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.10 on 2024-04-29 14:37 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('netbox_topology_views', '0007_individualoptions_group_locations_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='individualoptions', + name='disable_smooth_cables', + field=models.BooleanField(default=False), + ), + ] \ No newline at end of file diff --git a/netbox_topology_views/models.py b/netbox_topology_views/models.py index 7c14a47..f52bf18 100644 --- a/netbox_topology_views/models.py +++ b/netbox_topology_views/models.py @@ -398,6 +398,9 @@ class IndividualOptions(NetBoxModel): draw_default_layout = models.BooleanField( default=False ) + disable_smooth_cables = models.BooleanField( + default=False + ) _netbox_private = True diff --git a/netbox_topology_views/views.py b/netbox_topology_views/views.py index ed1be4b..c1843d2 100644 --- a/netbox_topology_views/views.py +++ b/netbox_topology_views/views.py @@ -238,6 +238,7 @@ def create_edge( edge_id: int, termination_a: Dict, termination_b: Dict, + disable_smooth: bool, circuit: Optional[Dict] = None, cable: Optional[Cable] = None, wireless: Optional[Dict] = None, @@ -300,6 +301,9 @@ def create_edge( if hasattr(cable, 'color') and cable.color != "": edge["color"] = "#" + cable.color + # Invert, because value must be False if disabled + edge["smooth"] = not disable_smooth + return edge @@ -339,6 +343,7 @@ def get_topology_data( group_locations: bool, group_racks: bool, group_id, + disable_smooth_cables: bool, ): supported_termination_types = [] @@ -436,6 +441,7 @@ def get_topology_data( circuit=circuit_model, termination_a=termination_a, termination_b=termination_b, + disable_smooth=individualOptions.disable_smooth_cables, ) ) @@ -505,6 +511,7 @@ def get_topology_data( termination_a=termination_a, termination_b=termination_b, power=True, + disable_smooth=individualOptions.disable_smooth_cables, ) ) @@ -543,7 +550,7 @@ def get_topology_data( edge_ids += 1 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 } - edges.append(create_edge(edge_id=edge_ids, termination_a=termination_a, termination_b=termination_b, interface=interface)) + edges.append(create_edge(edge_id=edge_ids, termination_a=termination_a, termination_b=termination_b, interface=interface, disable_smooth=individualOptions.disable_smooth_cables)) nodes_devices[interface.device.id] = interface.device nodes_devices[destination.device.id] = destination.device @@ -623,6 +630,7 @@ def get_topology_data( cable=link.cable, termination_a=termination_a, termination_b=termination_b, + disable_smooth=individualOptions.disable_smooth_cables, ) ) @@ -662,6 +670,7 @@ def get_topology_data( termination_a=termination_a, termination_b=termination_b, wireless=wireless, + disable_smooth=individualOptions.disable_smooth_cables, ) ) @@ -756,6 +765,7 @@ def get(self, request): group_locations=group_locations, group_racks=group_racks, group_id=group_id, + disable_smooth_cables=individualOptions.disable_smooth_cables, ) else: @@ -1137,6 +1147,7 @@ def get(self, request): 'group_locations': queryset.group_locations, 'group_racks': queryset.group_racks, 'draw_default_layout': queryset.draw_default_layout, + 'disable_smooth_cables': queryset.disable_smooth_cables, }, ) From 5de915749d6ebe6edeb908b90f2f2e2d57b9a3a5 Mon Sep 17 00:00:00 2001 From: Daniel Bremer Date: Thu, 2 May 2024 17:20:34 +0200 Subject: [PATCH 2/9] rename 'disable_smooth_cables' to 'straight_cables' --- netbox_topology_views/api/serializers.py | 2 +- netbox_topology_views/api/views.py | 2 +- netbox_topology_views/forms.py | 8 +++---- .../migrations/008_disable_smooth_cables.py | 2 +- netbox_topology_views/models.py | 2 +- netbox_topology_views/views.py | 21 +++++++++---------- 6 files changed, 18 insertions(+), 19 deletions(-) diff --git a/netbox_topology_views/api/serializers.py b/netbox_topology_views/api/serializers.py index 800886e..a5b5586 100644 --- a/netbox_topology_views/api/serializers.py +++ b/netbox_topology_views/api/serializers.py @@ -50,4 +50,4 @@ class Meta: class IndividualOptionsSerializer(NetBoxModelSerializer): class Meta: 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", "draw_default_layout", "disable_smooth_cables") + 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", "draw_default_layout", "straight_cables") diff --git a/netbox_topology_views/api/views.py b/netbox_topology_views/api/views.py index 0a22ae1..dc1fa95 100644 --- a/netbox_topology_views/api/views.py +++ b/netbox_topology_views/api/views.py @@ -153,7 +153,7 @@ def list(self, request): group_locations=group_locations, group_racks=group_racks, group_id=group_id, - disable_smooth_cables=individualOptions.disable_smooth_cables, + straight_cables=individualOptions.straight_cables, ) xml_data = export_data_to_xml(topo_data).decode('utf-8') diff --git a/netbox_topology_views/forms.py b/netbox_topology_views/forms.py index 1a7ac1d..8713c06 100644 --- a/netbox_topology_views/forms.py +++ b/netbox_topology_views/forms.py @@ -461,7 +461,7 @@ class IndividualOptionsForm(NetBoxModelForm): 'group_locations', 'group_racks', 'draw_default_layout', - 'disable_smooth_cables', + 'straight_cables', ), ), ) @@ -590,8 +590,8 @@ class IndividualOptionsForm(NetBoxModelForm): help_text=_('Enable this option if you want to draw the topology on ' 'the initial load (when you go to the topology plugin page).') ) - disable_smooth_cables = forms.BooleanField( - label=('Disable Smooth Cables'), + straight_cables = forms.BooleanField( + label=('Use Straight Cables'), required=False, initial=False, help_text=_('Enable this option if you want to draw cables as straight lines ' @@ -605,5 +605,5 @@ class Meta: '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', 'draw_default_layout', - 'disable_smooth_cables' + 'straight_cables' ] diff --git a/netbox_topology_views/migrations/008_disable_smooth_cables.py b/netbox_topology_views/migrations/008_disable_smooth_cables.py index 493b202..23bb490 100644 --- a/netbox_topology_views/migrations/008_disable_smooth_cables.py +++ b/netbox_topology_views/migrations/008_disable_smooth_cables.py @@ -12,7 +12,7 @@ class Migration(migrations.Migration): operations = [ migrations.AddField( model_name='individualoptions', - name='disable_smooth_cables', + name='straight_cables', field=models.BooleanField(default=False), ), ] \ No newline at end of file diff --git a/netbox_topology_views/models.py b/netbox_topology_views/models.py index f52bf18..0363fd4 100644 --- a/netbox_topology_views/models.py +++ b/netbox_topology_views/models.py @@ -398,7 +398,7 @@ class IndividualOptions(NetBoxModel): draw_default_layout = models.BooleanField( default=False ) - disable_smooth_cables = models.BooleanField( + straight_cables = models.BooleanField( default=False ) diff --git a/netbox_topology_views/views.py b/netbox_topology_views/views.py index c1843d2..33983cf 100644 --- a/netbox_topology_views/views.py +++ b/netbox_topology_views/views.py @@ -238,7 +238,7 @@ def create_edge( edge_id: int, termination_a: Dict, termination_b: Dict, - disable_smooth: bool, + straight_cables: bool, circuit: Optional[Dict] = None, cable: Optional[Cable] = None, wireless: Optional[Dict] = None, @@ -301,8 +301,7 @@ def create_edge( if hasattr(cable, 'color') and cable.color != "": edge["color"] = "#" + cable.color - # Invert, because value must be False if disabled - edge["smooth"] = not disable_smooth + edge["smooth"] = straight_cables return edge @@ -343,7 +342,7 @@ def get_topology_data( group_locations: bool, group_racks: bool, group_id, - disable_smooth_cables: bool, + straight_cables: bool, ): supported_termination_types = [] @@ -441,7 +440,7 @@ def get_topology_data( circuit=circuit_model, termination_a=termination_a, termination_b=termination_b, - disable_smooth=individualOptions.disable_smooth_cables, + straight_cables=individualOptions.straight_cables, ) ) @@ -511,7 +510,7 @@ def get_topology_data( termination_a=termination_a, termination_b=termination_b, power=True, - disable_smooth=individualOptions.disable_smooth_cables, + straight_cables=individualOptions.straight_cables, ) ) @@ -550,7 +549,7 @@ def get_topology_data( edge_ids += 1 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 } - edges.append(create_edge(edge_id=edge_ids, termination_a=termination_a, termination_b=termination_b, interface=interface, disable_smooth=individualOptions.disable_smooth_cables)) + edges.append(create_edge(edge_id=edge_ids, termination_a=termination_a, termination_b=termination_b, interface=interface, straight_cables=individualOptions.straight_cables)) nodes_devices[interface.device.id] = interface.device nodes_devices[destination.device.id] = destination.device @@ -630,7 +629,7 @@ def get_topology_data( cable=link.cable, termination_a=termination_a, termination_b=termination_b, - disable_smooth=individualOptions.disable_smooth_cables, + straight_cables=individualOptions.straight_cables, ) ) @@ -670,7 +669,7 @@ def get_topology_data( termination_a=termination_a, termination_b=termination_b, wireless=wireless, - disable_smooth=individualOptions.disable_smooth_cables, + straight_cables=individualOptions.straight_cables, ) ) @@ -765,7 +764,7 @@ def get(self, request): group_locations=group_locations, group_racks=group_racks, group_id=group_id, - disable_smooth_cables=individualOptions.disable_smooth_cables, + straight_cables=individualOptions.straight_cables, ) else: @@ -1147,7 +1146,7 @@ def get(self, request): 'group_locations': queryset.group_locations, 'group_racks': queryset.group_racks, 'draw_default_layout': queryset.draw_default_layout, - 'disable_smooth_cables': queryset.disable_smooth_cables, + 'straight_cables': queryset.straight_cables, }, ) From e44a8ae5339358d2f886ef6bb6abd09a5f5fe40d Mon Sep 17 00:00:00 2001 From: Daniel Bremer Date: Thu, 2 May 2024 17:23:28 +0200 Subject: [PATCH 3/9] missed one in renaming --- .../{008_disable_smooth_cables.py => 0008_straight_cables.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename netbox_topology_views/migrations/{008_disable_smooth_cables.py => 0008_straight_cables.py} (100%) diff --git a/netbox_topology_views/migrations/008_disable_smooth_cables.py b/netbox_topology_views/migrations/0008_straight_cables.py similarity index 100% rename from netbox_topology_views/migrations/008_disable_smooth_cables.py rename to netbox_topology_views/migrations/0008_straight_cables.py From adc3d9631f5266c58c3569c1387e7eac3c85ea0f Mon Sep 17 00:00:00 2001 From: Daniel Bremer Date: Thu, 2 May 2024 17:29:18 +0200 Subject: [PATCH 4/9] fix inverted logic --- netbox_topology_views/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/netbox_topology_views/views.py b/netbox_topology_views/views.py index 33983cf..283e5f6 100644 --- a/netbox_topology_views/views.py +++ b/netbox_topology_views/views.py @@ -301,7 +301,8 @@ def create_edge( if hasattr(cable, 'color') and cable.color != "": edge["color"] = "#" + cable.color - edge["smooth"] = straight_cables + # if straight_cables == True: edge["smooth"] = False + edge["smooth"] = not straight_cables return edge From 92eb719ec847c3ef0b4ffe2a00aed6cc34b44188 Mon Sep 17 00:00:00 2001 From: Daniel Bremer Date: Tue, 7 May 2024 10:46:44 +0200 Subject: [PATCH 5/9] add GET param and option to DeviceFilterForm --- netbox_topology_views/api/views.py | 5 +++-- netbox_topology_views/forms.py | 5 ++++- netbox_topology_views/utils.py | 9 +++++++-- netbox_topology_views/views.py | 15 ++++++++------- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/netbox_topology_views/api/views.py b/netbox_topology_views/api/views.py index dc1fa95..d22667c 100644 --- a/netbox_topology_views/api/views.py +++ b/netbox_topology_views/api/views.py @@ -109,7 +109,7 @@ def list(self, request): if request.GET: - filter_id, 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,show_neighbors = get_query_settings(request) + filter_id, 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, show_neighbors, straight_cables = get_query_settings(request) # Read options from saved filters as NetBox does not handle custom plugin filters if "filter_id" in request.GET and request.GET["filter_id"] != '': @@ -128,6 +128,7 @@ def list(self, request): if group_locations == False and 'group_locations' in saved_filter_params: group_locations = saved_filter_params['group_locations'] if group_racks == False and 'group_racks' in saved_filter_params: group_racks = saved_filter_params['group_racks'] 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: show_neighbors = saved_filter_params['straight_cables'] except SavedFilter.DoesNotExist: # filter_id not found pass except Exception as inst: @@ -153,7 +154,7 @@ def list(self, request): group_locations=group_locations, group_racks=group_racks, group_id=group_id, - straight_cables=individualOptions.straight_cables, + straight_cables=straight_cables, ) xml_data = export_data_to_xml(topo_data).decode('utf-8') diff --git a/netbox_topology_views/forms.py b/netbox_topology_views/forms.py index 8713c06..bcf536a 100644 --- a/netbox_topology_views/forms.py +++ b/netbox_topology_views/forms.py @@ -36,7 +36,7 @@ class DeviceFilterForm( (_('Options'), ( 'group', '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_sites', 'group_locations', 'group_racks', 'enable_straight_cables' )), (_('Device'), ('id',)), (_('Location'), ('region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id')), @@ -268,6 +268,9 @@ class DeviceFilterForm( group_racks = forms.BooleanField( label =_('Group Racks'), required=False, initial=False ) + enable_straight_cables = forms.BooleanField( + label = _('Straight Cables', required=False, initial=False) + ) class CoordinateGroupsForm(NetBoxModelForm): fieldsets = ( diff --git a/netbox_topology_views/utils.py b/netbox_topology_views/utils.py index a23fbba..8e4ec40 100644 --- a/netbox_topology_views/utils.py +++ b/netbox_topology_views/utils.py @@ -177,8 +177,13 @@ def get_query_settings(request): if "show_neighbors" in request.GET: if request.GET["show_neighbors"] == "on" : show_neighbors = True - - return filter_id, 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, show_neighbors + + straight_cables = False + if "straight_cables" in request.GET: + if request.GET["straight_cables"] == "on": + straight_cables = True + + return filter_id, 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, show_neighbors, straight_cables class LinePattern(): wireless = [2, 10, 2, 10] diff --git a/netbox_topology_views/views.py b/netbox_topology_views/views.py index 283e5f6..86d993a 100644 --- a/netbox_topology_views/views.py +++ b/netbox_topology_views/views.py @@ -441,7 +441,7 @@ def get_topology_data( circuit=circuit_model, termination_a=termination_a, termination_b=termination_b, - straight_cables=individualOptions.straight_cables, + straight_cables=straight_cables, ) ) @@ -511,7 +511,7 @@ def get_topology_data( termination_a=termination_a, termination_b=termination_b, power=True, - straight_cables=individualOptions.straight_cables, + straight_cables=straight_cables, ) ) @@ -550,7 +550,7 @@ def get_topology_data( edge_ids += 1 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 } - edges.append(create_edge(edge_id=edge_ids, termination_a=termination_a, termination_b=termination_b, interface=interface, straight_cables=individualOptions.straight_cables)) + edges.append(create_edge(edge_id=edge_ids, termination_a=termination_a, termination_b=termination_b, interface=interface, straight_cables=straight_cables)) nodes_devices[interface.device.id] = interface.device nodes_devices[destination.device.id] = destination.device @@ -630,7 +630,7 @@ def get_topology_data( cable=link.cable, termination_a=termination_a, termination_b=termination_b, - straight_cables=individualOptions.straight_cables, + straight_cables=straight_cables, ) ) @@ -670,7 +670,7 @@ def get_topology_data( termination_a=termination_a, termination_b=termination_b, wireless=wireless, - straight_cables=individualOptions.straight_cables, + straight_cables=straight_cables, ) ) @@ -719,7 +719,7 @@ def get(self, request): if request.GET: - filter_id, 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, show_neighbors = get_query_settings(request) + filter_id, 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, show_neighbors, straight_cables = get_query_settings(request) # Read options from saved filters as NetBox does not handle custom plugin filters if "filter_id" in request.GET and request.GET["filter_id"] != '': @@ -738,6 +738,7 @@ def get(self, request): if group_locations == False and 'group_locations' in saved_filter_params: group_locations = saved_filter_params['group_locations'] if group_racks == False and 'group_racks' in saved_filter_params: group_racks = saved_filter_params['group_racks'] 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'] except SavedFilter.DoesNotExist: # filter_id not found pass except Exception as inst: @@ -765,7 +766,7 @@ def get(self, request): group_locations=group_locations, group_racks=group_racks, group_id=group_id, - straight_cables=individualOptions.straight_cables, + straight_cables=straight_cables, ) else: From 073e1e2f23ba713a7da2465c4132459470efd396 Mon Sep 17 00:00:00 2001 From: Daniel Bremer Date: Tue, 7 May 2024 10:49:25 +0200 Subject: [PATCH 6/9] fix syntax error --- netbox_topology_views/forms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox_topology_views/forms.py b/netbox_topology_views/forms.py index bcf536a..7cbf691 100644 --- a/netbox_topology_views/forms.py +++ b/netbox_topology_views/forms.py @@ -269,7 +269,7 @@ class DeviceFilterForm( label =_('Group Racks'), required=False, initial=False ) enable_straight_cables = forms.BooleanField( - label = _('Straight Cables', required=False, initial=False) + label = _('Straight Cables'), required=False, initial=False ) class CoordinateGroupsForm(NetBoxModelForm): From 81d0814a6c275d34edc3e171e6943a5f9acbb23d Mon Sep 17 00:00:00 2001 From: Daniel Bremer Date: Tue, 7 May 2024 10:54:16 +0200 Subject: [PATCH 7/9] rename var --- netbox_topology_views/forms.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/netbox_topology_views/forms.py b/netbox_topology_views/forms.py index 7cbf691..ff7c6bf 100644 --- a/netbox_topology_views/forms.py +++ b/netbox_topology_views/forms.py @@ -36,7 +36,7 @@ class DeviceFilterForm( (_('Options'), ( 'group', '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', 'enable_straight_cables' + 'group_sites', 'group_locations', 'group_racks', 'straight_cables' )), (_('Device'), ('id',)), (_('Location'), ('region_id', 'site_group_id', 'site_id', 'location_id', 'rack_id')), @@ -268,7 +268,7 @@ class DeviceFilterForm( group_racks = forms.BooleanField( label =_('Group Racks'), required=False, initial=False ) - enable_straight_cables = forms.BooleanField( + straight_cables = forms.BooleanField( label = _('Straight Cables'), required=False, initial=False ) From 06d036118d91ab3b72d705329da63369f754b829 Mon Sep 17 00:00:00 2001 From: Daniel Bremer Date: Tue, 7 May 2024 10:54:26 +0200 Subject: [PATCH 8/9] add missing query field --- netbox_topology_views/views.py | 1 + 1 file changed, 1 insertion(+) diff --git a/netbox_topology_views/views.py b/netbox_topology_views/views.py index 86d993a..dc59ef1 100644 --- a/netbox_topology_views/views.py +++ b/netbox_topology_views/views.py @@ -794,6 +794,7 @@ def get(self, request): q['draw_init'] = "true" else: q['draw_init'] = "false" + if individualOptions.straight_cables: q['straight_cables'] = "on" query_string = q.urlencode() return HttpResponseRedirect(f"{request.path}?{query_string}") From 5a1081ec1fc96c9a8ffa4ad98744f71b96530c6f Mon Sep 17 00:00:00 2001 From: mvanhaverbeke Date: Mon, 8 Jul 2024 15:34:33 +0200 Subject: [PATCH 9/9] netbox v4 support --- netbox_topology_views/forms.py | 5 ++++- netbox_topology_views/utils.py | 2 +- netbox_topology_views/views.py | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/netbox_topology_views/forms.py b/netbox_topology_views/forms.py index 5ed520b..d3b9d19 100644 --- a/netbox_topology_views/forms.py +++ b/netbox_topology_views/forms.py @@ -311,7 +311,10 @@ class DeviceFilterForm( ) ) straight_cables = forms.BooleanField( - label=_('Straight Cables'), required=False, initial=False + label=_('Straight Cables'), required=False, initial=False, + widget=forms.Select( + choices=BOOLEAN_WITH_BLANK_CHOICES + ) ) class CoordinateGroupsForm(NetBoxModelForm): diff --git a/netbox_topology_views/utils.py b/netbox_topology_views/utils.py index b69b84b..0b66efd 100644 --- a/netbox_topology_views/utils.py +++ b/netbox_topology_views/utils.py @@ -180,7 +180,7 @@ def get_query_settings(request): straight_cables = False if "straight_cables" in request.GET: - if request.GET["straight_cables"] == "on": + if request.GET["straight_cables"] == "True": straight_cables = True return filter_id, 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, show_neighbors, straight_cables diff --git a/netbox_topology_views/views.py b/netbox_topology_views/views.py index 80c2846..fe09422 100644 --- a/netbox_topology_views/views.py +++ b/netbox_topology_views/views.py @@ -790,11 +790,11 @@ def get(self, request): if individualOptions.group_sites: q['group_sites'] = "True" if individualOptions.group_locations: q['group_locations'] = "True" if individualOptions.group_racks: q['group_racks'] = "True" + if individualOptions.straight_cables: q['straight_cables'] = "True" if individualOptions.draw_default_layout: q['draw_init'] = "True" else: q['draw_init'] = "False" - if individualOptions.straight_cables: q['straight_cables'] = "on" query_string = q.urlencode() return HttpResponseRedirect(f"{request.path}?{query_string}")