From 5e1d5d29374233ad742d8522fadbdde71216eb56 Mon Sep 17 00:00:00 2001 From: mattieserver <3049868+mattieserver@users.noreply.github.com> Date: Wed, 24 Aug 2022 14:07:26 +0200 Subject: [PATCH] added always_save_coordinates (#144) --- README.md | 1 + netbox_topology_views/__init__.py | 1 + netbox_topology_views/forms.py | 5 ++--- netbox_topology_views/views.py | 3 +++ 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index eb3a0a4..1598046 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ PLUGINS_CONFIG = { | preselected_device_roles | ['Firewall', 'Router', 'Distribution Switch', 'Core Switch', 'Internal Switch', 'Access Switch', 'Server', 'Storage', 'Backup', 'Wireless AP'] | The full name of the device roles you want to pre select in the global view. Note that this is case sensitive| | preselected_intermediate_dev_roles | ['Patch-panel'] | The full name of the device roles you want to display in the global view when using end-to-end connections mode. Note that this is case sensitive| | allow_coordinates_saving | False | (bool) Set to true if you use the custom coordinates fields and want to save the coordinates | +| always_save_coordinates | False | (bool) Set if you want to enable the option to save coordinates by default | | ignore_cable_type | ['power outlet', 'power port'] | The cable types that you want to ignore in the views | | preselected_tags | '[]' | The name of tags you want to preload | | enable_circuit_terminations | False | (bool) Set to true if you want to see circuit terminations in the topology | diff --git a/netbox_topology_views/__init__.py b/netbox_topology_views/__init__.py index f24814d..fd2a67d 100644 --- a/netbox_topology_views/__init__.py +++ b/netbox_topology_views/__init__.py @@ -16,6 +16,7 @@ class TopologyViewsConfig(PluginConfig): 'ignore_cable_type': ['power outlet','power port'], 'device_img': ['access-switch', 'core-switch', 'firewall', 'router', 'distribution-switch', 'backup', 'storage', 'wan-network', 'wireless-ap', 'server', 'internal-switch', 'isp-cpe-material', 'non-racked-devices', 'power-units'], 'allow_coordinates_saving': False, + 'always_save_coordinates': False, 'preselected_tags' : [], 'enable_circuit_terminations': False, 'draw_default_layout': False diff --git a/netbox_topology_views/forms.py b/netbox_topology_views/forms.py index b40246b..5982912 100644 --- a/netbox_topology_views/forms.py +++ b/netbox_topology_views/forms.py @@ -15,7 +15,7 @@ from django.conf import settings from netbox.forms import NetBoxModelFilterSetForm from utilities.forms import (TagFilterField, DynamicModelMultipleChoiceField, MultipleChoiceField) -allow_coordinates_saving = settings.PLUGINS_CONFIG["netbox_topology_views"]["allow_coordinates_saving"] +allow_coordinates_saving = bool(settings.PLUGINS_CONFIG["netbox_topology_views"]["allow_coordinates_saving"]) end2end = settings.PLUGINS_CONFIG["netbox_topology_views"]["end2end_connections"] @@ -75,8 +75,7 @@ class DeviceFilterForm(TenancyFilterForm, NetBoxModelFilterSetForm): save_coords = forms.BooleanField( label=_("Save Coordinates"), required=False, - disabled=(not allow_coordinates_saving), - initial=False + disabled=(not allow_coordinates_saving) ) status = MultipleChoiceField( choices=DeviceStatusChoices, diff --git a/netbox_topology_views/views.py b/netbox_topology_views/views.py index ee5f364..9fbbc85 100644 --- a/netbox_topology_views/views.py +++ b/netbox_topology_views/views.py @@ -305,6 +305,7 @@ class TopologyHomeView(PermissionRequiredMixin, View): preselected_device_roles = settings.PLUGINS_CONFIG["netbox_topology_views"]["preselected_device_roles"] preselected_intermediate_dev_roles = settings.PLUGINS_CONFIG["netbox_topology_views"]["preselected_intermediate_dev_roles"] preselected_tags = settings.PLUGINS_CONFIG["netbox_topology_views"]["preselected_tags"] + always_save_coordinates = bool(settings.PLUGINS_CONFIG["netbox_topology_views"]["always_save_coordinates"]) q_device_role_id = DeviceRole.objects.filter(name__in=preselected_device_roles).values_list("id", flat=True) q_intermediate_dev_role_id = DeviceRole.objects.filter(name__in=preselected_intermediate_dev_roles).values_list("id", flat=True) @@ -315,6 +316,8 @@ class TopologyHomeView(PermissionRequiredMixin, View): q.setlist("intermediate_dev_role_id", list(q_intermediate_dev_role_id)) q.setlist("tag", list(q_tags)) q["draw_init"] = settings.PLUGINS_CONFIG["netbox_topology_views"]["draw_default_layout"] + if always_save_coordinates: + q["save_coords"] = "on" query_string = q.urlencode() return HttpResponseRedirect(request.path + "?" + query_string)