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:
@ -1,5 +1,13 @@
|
||||
# NetBox v3.0
|
||||
|
||||
## v2.11.12 (2021-08-23)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* [#7070](https://github.com/netbox-community/netbox/issues/7070) - Fix exception when filtering by prefix max length in UI
|
||||
|
||||
---
|
||||
|
||||
## v3.0.0 (2021-08-30)
|
||||
|
||||
!!! warning "Existing Deployments Must Upgrade from v2.11"
|
||||
|
@ -216,7 +216,7 @@ class PrefixFilterSet(PrimaryModelFilterSet, TenancyFilterSet):
|
||||
children = MultiValueNumberFilter(
|
||||
field_name='_children'
|
||||
)
|
||||
mask_length = django_filters.NumberFilter(
|
||||
mask_length = MultiValueNumberFilter(
|
||||
field_name='prefix',
|
||||
lookup_expr='net_mask_length'
|
||||
)
|
||||
|
@ -658,11 +658,11 @@ class PrefixFilterForm(BootstrapMixin, TenancyFilterForm, CustomFieldModelFilter
|
||||
label=_('Address family'),
|
||||
widget=StaticSelect()
|
||||
)
|
||||
mask_length = forms.ChoiceField(
|
||||
mask_length = forms.MultipleChoiceField(
|
||||
required=False,
|
||||
choices=PREFIX_MASK_LENGTH_CHOICES,
|
||||
label=_('Mask length'),
|
||||
widget=StaticSelect()
|
||||
widget=StaticSelectMultiple()
|
||||
)
|
||||
vrf_id = DynamicModelMultipleChoiceField(
|
||||
queryset=VRF.objects.all(),
|
||||
|
@ -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):
|
||||
|
@ -411,16 +411,16 @@ 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:
|
||||
if filter_name not in query_params:
|
||||
if filter_name not in querydict:
|
||||
continue
|
||||
|
||||
bound_field = form.fields[filter_name].get_bound_field(form, filter_name)
|
||||
querydict = query_params.copy()
|
||||
querydict.pop(filter_name)
|
||||
display_value = ', '.join(get_selected_values(form, filter_name))
|
||||
display_value = ', '.join([str(v) for v in get_selected_values(form, filter_name)])
|
||||
|
||||
applied_filters.append({
|
||||
'name': filter_name,
|
||||
|
Reference in New Issue
Block a user