1
0
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:
jeremystretch
2021-09-17 16:55:32 -04:00
parent 383cdb5340
commit 713e79c1a9
3 changed files with 26 additions and 21 deletions

View File

@ -24,6 +24,7 @@
* [#7273](https://github.com/netbox-community/netbox/issues/7273) - Fix natural ordering of device components in UI form fields * [#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 * [#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 * [#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
--- ---

View File

@ -122,28 +122,32 @@ def get_selected_values(form, field_name):
form.is_valid() form.is_valid()
filter_data = form.cleaned_data.get(field_name) filter_data = form.cleaned_data.get(field_name)
field = form.fields[field_name] field = form.fields[field_name]
# Selection field
if hasattr(field, 'choices'): # Non-selection field
try: 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) 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 hasattr(field, 'null_option'):
# If the field has a `null_option` attribute set and it is selected, # If the field has a `null_option` attribute set and it is selected,
# add it to the field's grouped choices. # add it to the field's grouped choices.
if field.null_option is not None and None in filter_data: 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 [ return values
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)]
def add_blank_choice(choices): def add_blank_choice(choices):

View File

@ -411,10 +411,10 @@ def applied_filters(form, query_params):
Display the active filters for a given filter form. Display the active filters for a given filter form.
""" """
form.is_valid() form.is_valid()
querydict = query_params.copy()
applied_filters = [] applied_filters = []
for filter_name in form.changed_data: for filter_name in form.changed_data:
querydict = query_params.copy()
if filter_name not in querydict: if filter_name not in querydict:
continue continue