Skip to content

Commit 713e79c

Browse files
committed
Fixes #7298: Restore missing object names from applied object list filters
1 parent 383cdb5 commit 713e79c

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

docs/release-notes/version-3.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
* [#7273](https://github.com/netbox-community/netbox/issues/7273) - Fix natural ordering of device components in UI form fields
2525
* [#7279](https://github.com/netbox-community/netbox/issues/7279) - Fix exception when tracing cable with no associated path
2626
* [#7282](https://github.com/netbox-community/netbox/issues/7282) - Fix KeyError exception when `INSECURE_SKIP_TLS_VERIFY` is true
27+
* [#7298](https://github.com/netbox-community/netbox/issues/7298) - Restore missing object names from applied object list filters
2728

2829
---
2930

netbox/utilities/forms/utils.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -122,28 +122,32 @@ def get_selected_values(form, field_name):
122122
form.is_valid()
123123
filter_data = form.cleaned_data.get(field_name)
124124
field = form.fields[field_name]
125-
# Selection field
126-
if hasattr(field, 'choices'):
127-
try:
128-
choices = unpack_grouped_choices(field.choices)
129-
130-
if hasattr(field, 'null_option'):
131-
# If the field has a `null_option` attribute set and it is selected,
132-
# add it to the field's grouped choices.
133-
if field.null_option is not None and None in filter_data:
134-
choices.append((settings.FILTERS_NULL_CHOICE_VALUE, field.null_option))
135-
136-
return [
137-
label for value, label in choices if str(value) in filter_data or None in filter_data
138-
]
139-
except TypeError:
140-
# Field uses dynamic choices. Show all that have been populated.
141-
return [
142-
subwidget.choice_label for subwidget in form[field_name].subwidgets
143-
]
144125

145126
# Non-selection field
146-
return [str(filter_data)]
127+
if not hasattr(field, 'choices'):
128+
return [str(filter_data)]
129+
130+
# Get choice labels
131+
if type(field.choices) is forms.models.ModelChoiceIterator:
132+
# Field uses dynamic choices: show all that have been populated on the widget
133+
values = [
134+
subwidget.choice_label for subwidget in form[field_name].subwidgets
135+
]
136+
137+
else:
138+
# Static selection field
139+
choices = unpack_grouped_choices(field.choices)
140+
values = [
141+
label for value, label in choices if str(value) in filter_data or None in filter_data
142+
]
143+
144+
if hasattr(field, 'null_option'):
145+
# If the field has a `null_option` attribute set and it is selected,
146+
# add it to the field's grouped choices.
147+
if field.null_option is not None and None in filter_data:
148+
values.append(field.null_option)
149+
150+
return values
147151

148152

149153
def add_blank_choice(choices):

netbox/utilities/templatetags/helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,10 @@ def applied_filters(form, query_params):
411411
Display the active filters for a given filter form.
412412
"""
413413
form.is_valid()
414-
querydict = query_params.copy()
415414

416415
applied_filters = []
417416
for filter_name in form.changed_data:
417+
querydict = query_params.copy()
418418
if filter_name not in querydict:
419419
continue
420420

0 commit comments

Comments
 (0)