Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added unique rack filter custom extension for quality of life improve… #118

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/117.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added unique rack filter_extension
djhoward12 marked this conversation as resolved.
Show resolved Hide resolved
14 changes: 13 additions & 1 deletion nautobot_floor_plan/filter_extensions.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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_has_floor_plan_tile": RelatedMembershipBooleanFilter(
field_name="floor_plan_tile",
label="Floor plan",
),
}
djhoward12 marked this conversation as resolved.
Show resolved Hide resolved

class RackGroupFilterExtension(PluginFilterExtension):
"""Add a filter to the RackGroupFilterSet in Nautobot core."""
Expand All @@ -34,4 +46,4 @@ class RackGroupFilterExtension(PluginFilterExtension):
}


filter_extensions = [RackFilterExtension, RackGroupFilterExtension]
filter_extensions = [RackFilterExtension, RackGroupFilterExtension, UniqueRackFilterExtension]
2 changes: 1 addition & 1 deletion nautobot_floor_plan/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class FloorPlanTileForm(NautobotModelForm):
rack = DynamicModelChoiceField(
queryset=Rack.objects.all(),
required=False,
query_params={"nautobot_floor_plan_floor_plan": "$floor_plan", "rack_group": "$rack_group"},
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(),
Expand Down