From 45988b9818e52da75e5199a2b1291012220a1a18 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Wed, 8 Sep 2021 11:11:52 -0400 Subject: [PATCH] Minor cleanup for get_selected_values() --- netbox/utilities/forms/utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/netbox/utilities/forms/utils.py b/netbox/utilities/forms/utils.py index 3297f7955..bb1f56c4d 100644 --- a/netbox/utilities/forms/utils.py +++ b/netbox/utilities/forms/utils.py @@ -1,6 +1,7 @@ import re from django import forms +from django.conf import settings from django.forms.models import fields_for_model from utilities.choices import unpack_grouped_choices @@ -124,17 +125,16 @@ def get_selected_values(form, field_name): # Selection field if hasattr(field, 'choices'): try: - grouped_choices = [(k, v) for k, v in field.choices] + 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: - grouped_choices.append((field.null_option, field.null_option)) + choices.append((settings.FILTERS_NULL_CHOICE_VALUE, field.null_option)) - choices = dict(unpack_grouped_choices(grouped_choices)) return [ - label for value, label in choices.items() if str(value) in filter_data or None in filter_data + 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.