diff --git a/docs/release-notes/version-3.0.md b/docs/release-notes/version-3.0.md index ee4f7aebe..644a2e652 100644 --- a/docs/release-notes/version-3.0.md +++ b/docs/release-notes/version-3.0.md @@ -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 --- diff --git a/netbox/utilities/forms/utils.py b/netbox/utilities/forms/utils.py index bb1f56c4d..7d2b79f02 100644 --- a/netbox/utilities/forms/utils.py +++ b/netbox/utilities/forms/utils.py @@ -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: - choices = unpack_grouped_choices(field.choices) - - 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)) - - 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)] + 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: + values.append(field.null_option) + + return values def add_blank_choice(choices): diff --git a/netbox/utilities/templatetags/helpers.py b/netbox/utilities/templatetags/helpers.py index 1b13fb2a8..615595f0f 100644 --- a/netbox/utilities/templatetags/helpers.py +++ b/netbox/utilities/templatetags/helpers.py @@ -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