mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Fixes #7298: Restore missing object names from applied object list filters
This commit is contained in:
@ -24,6 +24,7 @@
|
||||
* [#7273](https://github.com/netbox-community/netbox/issues/7273) - Fix natural ordering of device components in UI form fields
|
||||
* [#7279](https://github.com/netbox-community/netbox/issues/7279) - Fix exception when tracing cable with no associated path
|
||||
* [#7282](https://github.com/netbox-community/netbox/issues/7282) - Fix KeyError exception when `INSECURE_SKIP_TLS_VERIFY` is true
|
||||
* [#7298](https://github.com/netbox-community/netbox/issues/7298) - Restore missing object names from applied object list filters
|
||||
|
||||
---
|
||||
|
||||
|
@ -122,28 +122,32 @@ def get_selected_values(form, field_name):
|
||||
form.is_valid()
|
||||
filter_data = form.cleaned_data.get(field_name)
|
||||
field = form.fields[field_name]
|
||||
# Selection field
|
||||
if hasattr(field, 'choices'):
|
||||
try:
|
||||
|
||||
# Non-selection field
|
||||
if not hasattr(field, 'choices'):
|
||||
return [str(filter_data)]
|
||||
|
||||
# Get choice labels
|
||||
if type(field.choices) is forms.models.ModelChoiceIterator:
|
||||
# Field uses dynamic choices: show all that have been populated on the widget
|
||||
values = [
|
||||
subwidget.choice_label for subwidget in form[field_name].subwidgets
|
||||
]
|
||||
|
||||
else:
|
||||
# Static selection field
|
||||
choices = unpack_grouped_choices(field.choices)
|
||||
values = [
|
||||
label for value, label in choices if str(value) in filter_data or None in filter_data
|
||||
]
|
||||
|
||||
if hasattr(field, 'null_option'):
|
||||
# If the field has a `null_option` attribute set and it is selected,
|
||||
# add it to the field's grouped choices.
|
||||
if field.null_option is not None and None in filter_data:
|
||||
choices.append((settings.FILTERS_NULL_CHOICE_VALUE, field.null_option))
|
||||
values.append(field.null_option)
|
||||
|
||||
return [
|
||||
label for value, label in choices if str(value) in filter_data or None in filter_data
|
||||
]
|
||||
except TypeError:
|
||||
# Field uses dynamic choices. Show all that have been populated.
|
||||
return [
|
||||
subwidget.choice_label for subwidget in form[field_name].subwidgets
|
||||
]
|
||||
|
||||
# Non-selection field
|
||||
return [str(filter_data)]
|
||||
return values
|
||||
|
||||
|
||||
def add_blank_choice(choices):
|
||||
|
@ -411,10 +411,10 @@ def applied_filters(form, query_params):
|
||||
Display the active filters for a given filter form.
|
||||
"""
|
||||
form.is_valid()
|
||||
querydict = query_params.copy()
|
||||
|
||||
applied_filters = []
|
||||
for filter_name in form.changed_data:
|
||||
querydict = query_params.copy()
|
||||
if filter_name not in querydict:
|
||||
continue
|
||||
|
||||
|
Reference in New Issue
Block a user