|
@@ -1,6 +1,7 @@
|
|
|
import re
|
|
import re
|
|
|
|
|
|
|
|
from django import forms
|
|
from django import forms
|
|
|
|
|
+from django.conf import settings
|
|
|
from django.forms.models import fields_for_model
|
|
from django.forms.models import fields_for_model
|
|
|
|
|
|
|
|
from utilities.choices import unpack_grouped_choices
|
|
from utilities.choices import unpack_grouped_choices
|
|
@@ -120,13 +121,20 @@ def get_selected_values(form, field_name):
|
|
|
if not hasattr(form, 'cleaned_data'):
|
|
if not hasattr(form, 'cleaned_data'):
|
|
|
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]
|
|
|
# Selection field
|
|
# Selection field
|
|
|
- if hasattr(form.fields[field_name], 'choices'):
|
|
|
|
|
|
|
+ if hasattr(field, 'choices'):
|
|
|
try:
|
|
try:
|
|
|
- choices = dict(unpack_grouped_choices(form.fields[field_name].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:
|
|
|
|
|
+ choices.append((settings.FILTERS_NULL_CHOICE_VALUE, field.null_option))
|
|
|
|
|
+
|
|
|
return [
|
|
return [
|
|
|
- label for value, label in choices.items() if str(value) in filter_data
|
|
|
|
|
|
|
+ label for value, label in choices if str(value) in filter_data or None in filter_data
|
|
|
]
|
|
]
|
|
|
except TypeError:
|
|
except TypeError:
|
|
|
# Field uses dynamic choices. Show all that have been populated.
|
|
# Field uses dynamic choices. Show all that have been populated.
|