1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

Fixes #7070: Fix exception when filtering by prefix max length in UI

This commit is contained in:
jeremystretch
2021-08-30 16:51:07 -04:00
parent fd16c47d2e
commit deb53d771d
5 changed files with 17 additions and 8 deletions

View File

@ -119,13 +119,14 @@ def get_selected_values(form, field_name):
"""
if not hasattr(form, 'cleaned_data'):
form.is_valid()
filter_data = form.cleaned_data.get(field_name)
# Selection field
if hasattr(form.fields[field_name], 'choices'):
try:
choices = dict(unpack_grouped_choices(form.fields[field_name].choices))
return [
label for value, label in choices.items() if value in form.cleaned_data[field_name]
label for value, label in choices.items() if str(value) in filter_data
]
except TypeError:
# Field uses dynamic choices. Show all that have been populated.
@ -134,7 +135,7 @@ def get_selected_values(form, field_name):
]
# Non-selection field
return [str(form.cleaned_data[field_name])]
return [str(filter_data)]
def add_blank_choice(choices):