From ce16cbb2e6120b65dd525778b27a0e09e6b28734 Mon Sep 17 00:00:00 2001 From: DJ Howard Date: Fri, 23 Aug 2024 13:40:04 -0400 Subject: [PATCH 1/5] Added unique rack filter custom extension for quality of life improvements --- changes/117.add | 1 + nautobot_floor_plan/filter_extensions.py | 14 +++++++++++++- nautobot_floor_plan/forms.py | 6 +++--- 3 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 changes/117.add diff --git a/changes/117.add b/changes/117.add new file mode 100644 index 0000000..756c95e --- /dev/null +++ b/changes/117.add @@ -0,0 +1 @@ +Added unique rack filter_extension \ No newline at end of file diff --git a/nautobot_floor_plan/filter_extensions.py b/nautobot_floor_plan/filter_extensions.py index f683db7..3a3629d 100644 --- a/nautobot_floor_plan/filter_extensions.py +++ b/nautobot_floor_plan/filter_extensions.py @@ -1,6 +1,7 @@ """Extensions to Nautobot core models' filtering functionality.""" import django_filters +from nautobot.apps.filters import RelatedMembershipBooleanFilter from nautobot.extras.plugins import PluginFilterExtension from nautobot_floor_plan import models @@ -19,6 +20,17 @@ class RackFilterExtension(PluginFilterExtension): ), } +class UniqueRackFilterExtension(PluginFilterExtension): + """Add a filter to ensure a Rack is only an option if it isn't installed.""" + + model = "dcim.rack" + + filterset_fields = { + "nautobot_floor_plan_unique_rack": RelatedMembershipBooleanFilter( + field_name="floor_plan_tile", + label="Floor plan", + ), + } class RackGroupFilterExtension(PluginFilterExtension): """Add a filter to the RackGroupFilterSet in Nautobot core.""" @@ -34,4 +46,4 @@ class RackGroupFilterExtension(PluginFilterExtension): } -filter_extensions = [RackFilterExtension, RackGroupFilterExtension] +filter_extensions = [RackFilterExtension, RackGroupFilterExtension, UniqueRackFilterExtension] diff --git a/nautobot_floor_plan/forms.py b/nautobot_floor_plan/forms.py index 127f30e..ac4e666 100644 --- a/nautobot_floor_plan/forms.py +++ b/nautobot_floor_plan/forms.py @@ -136,9 +136,9 @@ class FloorPlanTileForm(NautobotModelForm): floor_plan = DynamicModelChoiceField(queryset=models.FloorPlan.objects.all()) rack = DynamicModelChoiceField( - queryset=Rack.objects.all(), - required=False, - query_params={"nautobot_floor_plan_floor_plan": "$floor_plan", "rack_group": "$rack_group"}, + queryset=Rack.objects.all(), + required=False, + query_params={"nautobot_floor_plan_floor_plan": "$floor_plan", "nautobot_floor_plan_unique_rack": False, "rack_group": "$rack_group"}, ) rack_group = DynamicModelChoiceField( queryset=RackGroup.objects.all(), From d8bc17b6f252320733fe88cc4f36816b67a3e670 Mon Sep 17 00:00:00 2001 From: DJ Howard Date: Fri, 23 Aug 2024 13:43:01 -0400 Subject: [PATCH 2/5] renamed changelog from add to added --- changes/{117.add => 117.added} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename changes/{117.add => 117.added} (100%) diff --git a/changes/117.add b/changes/117.added similarity index 100% rename from changes/117.add rename to changes/117.added From f3b41496b1b7add99d7b8acdc8c7ebd32c885b88 Mon Sep 17 00:00:00 2001 From: DJ Howard Date: Mon, 26 Aug 2024 09:36:19 -0400 Subject: [PATCH 3/5] updated filter name per core best practices added back white space. --- nautobot_floor_plan/filter_extensions.py | 2 +- nautobot_floor_plan/forms.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nautobot_floor_plan/filter_extensions.py b/nautobot_floor_plan/filter_extensions.py index 3a3629d..4f665da 100644 --- a/nautobot_floor_plan/filter_extensions.py +++ b/nautobot_floor_plan/filter_extensions.py @@ -26,7 +26,7 @@ class UniqueRackFilterExtension(PluginFilterExtension): model = "dcim.rack" filterset_fields = { - "nautobot_floor_plan_unique_rack": RelatedMembershipBooleanFilter( + "nautobot_floor_plan_has_floor_plan_tile": RelatedMembershipBooleanFilter( field_name="floor_plan_tile", label="Floor plan", ), diff --git a/nautobot_floor_plan/forms.py b/nautobot_floor_plan/forms.py index ac4e666..12f5a63 100644 --- a/nautobot_floor_plan/forms.py +++ b/nautobot_floor_plan/forms.py @@ -136,9 +136,9 @@ class FloorPlanTileForm(NautobotModelForm): floor_plan = DynamicModelChoiceField(queryset=models.FloorPlan.objects.all()) rack = DynamicModelChoiceField( - queryset=Rack.objects.all(), - required=False, - query_params={"nautobot_floor_plan_floor_plan": "$floor_plan", "nautobot_floor_plan_unique_rack": False, "rack_group": "$rack_group"}, + queryset=Rack.objects.all(), + required=False, + query_params={"nautobot_floor_plan_floor_plan": "$floor_plan", "nautobot_floor_plan_has_floor_plan_tile": False, "rack_group": "$rack_group"}, ) rack_group = DynamicModelChoiceField( queryset=RackGroup.objects.all(), From 9979c28de123f10cfe64ab25fa14937948249a0b Mon Sep 17 00:00:00 2001 From: DJ Howard <45186384+djhoward12@users.noreply.github.com> Date: Mon, 26 Aug 2024 09:52:14 -0400 Subject: [PATCH 4/5] Update changes/117.added Co-authored-by: Joe Wesch <10467633+joewesch@users.noreply.github.com> --- changes/117.added | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changes/117.added b/changes/117.added index 756c95e..f465a72 100644 --- a/changes/117.added +++ b/changes/117.added @@ -1 +1 @@ -Added unique rack filter_extension \ No newline at end of file +Added filter extension to be able to filter racks that are assigned/unassigned to a floor plan tile. \ No newline at end of file From 9bbf332ca0c07ae83286d6e484ad54c219111b68 Mon Sep 17 00:00:00 2001 From: DJ Howard Date: Mon, 26 Aug 2024 10:41:51 -0400 Subject: [PATCH 5/5] remvoved UniqueRackFilter class and moved filter_set field content under RackFilterExtension --- nautobot_floor_plan/filter_extensions.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/nautobot_floor_plan/filter_extensions.py b/nautobot_floor_plan/filter_extensions.py index 4f665da..8b1ab2c 100644 --- a/nautobot_floor_plan/filter_extensions.py +++ b/nautobot_floor_plan/filter_extensions.py @@ -18,20 +18,13 @@ class RackFilterExtension(PluginFilterExtension): field_name="location__floor_plan", label="Floor plan", ), - } - -class UniqueRackFilterExtension(PluginFilterExtension): - """Add a filter to ensure a Rack is only an option if it isn't installed.""" - - model = "dcim.rack" - - filterset_fields = { "nautobot_floor_plan_has_floor_plan_tile": RelatedMembershipBooleanFilter( field_name="floor_plan_tile", - label="Floor plan", + label="Floor Plan Tile", ), } + class RackGroupFilterExtension(PluginFilterExtension): """Add a filter to the RackGroupFilterSet in Nautobot core.""" @@ -46,4 +39,4 @@ class RackGroupFilterExtension(PluginFilterExtension): } -filter_extensions = [RackFilterExtension, RackGroupFilterExtension, UniqueRackFilterExtension] +filter_extensions = [RackFilterExtension, RackGroupFilterExtension]