mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-12 11:29:36 -06:00
Fix applied_filters template tag to use field-type-specific lookup labelsresolves
E.g. resolves gt="after" for dates vs "greater than" for numbers
This commit is contained in:
parent
9d60342ec7
commit
42df6be604
@ -208,8 +208,8 @@ class FilterModifierMixin:
|
|||||||
Returns an empty list for fields that should not be enhanced.
|
Returns an empty list for fields that should not be enhanced.
|
||||||
"""
|
"""
|
||||||
for field_class in field.__class__.__mro__:
|
for field_class in field.__class__.__mro__:
|
||||||
if field_class in FORM_FIELD_LOOKUPS:
|
if field_lookups := FORM_FIELD_LOOKUPS.get(field_class):
|
||||||
return FORM_FIELD_LOOKUPS[field_class]
|
return field_lookups
|
||||||
|
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|||||||
@ -414,13 +414,6 @@ def applied_filters(context, model, form, query_params):
|
|||||||
user = context['request'].user
|
user = context['request'].user
|
||||||
form.is_valid() # Ensure cleaned_data has been set
|
form.is_valid() # Ensure cleaned_data has been set
|
||||||
|
|
||||||
# Build lookup labels from FORM_FIELD_LOOKUPS
|
|
||||||
lookup_labels = {}
|
|
||||||
for field_lookups in FORM_FIELD_LOOKUPS.values():
|
|
||||||
for lookup_code, lookup_label in field_lookups:
|
|
||||||
if lookup_code not in ('exact', 'empty_true', 'empty_false'):
|
|
||||||
lookup_labels[lookup_code] = lookup_label
|
|
||||||
|
|
||||||
applied_filters = []
|
applied_filters = []
|
||||||
for filter_name in form.changed_data:
|
for filter_name in form.changed_data:
|
||||||
if filter_name not in form.cleaned_data:
|
if filter_name not in form.cleaned_data:
|
||||||
@ -459,14 +452,27 @@ def applied_filters(context, model, form, query_params):
|
|||||||
# Get display value
|
# Get display value
|
||||||
display_value = ', '.join([str(v) for v in get_selected_values(form, filter_name)])
|
display_value = ', '.join([str(v) for v in get_selected_values(form, filter_name)])
|
||||||
|
|
||||||
|
# Get the correct lookup label for this field's type
|
||||||
|
lookup_label = None
|
||||||
|
if modifier != 'exact':
|
||||||
|
field = form.fields[filter_name]
|
||||||
|
for field_class in field.__class__.__mro__:
|
||||||
|
if field_lookups := FORM_FIELD_LOOKUPS.get(field_class):
|
||||||
|
for lookup_code, label in field_lookups:
|
||||||
|
if lookup_code == modifier:
|
||||||
|
lookup_label = label
|
||||||
|
break
|
||||||
|
if lookup_label:
|
||||||
|
break
|
||||||
|
|
||||||
# Special handling for empty lookup (boolean value)
|
# Special handling for empty lookup (boolean value)
|
||||||
if modifier == 'empty':
|
if modifier == 'empty':
|
||||||
if display_value.lower() in ('true', '1'):
|
if display_value.lower() in ('true', '1'):
|
||||||
link_text = f'{bound_field.label} {_("is empty")}'
|
link_text = f'{bound_field.label} {_("is empty")}'
|
||||||
else:
|
else:
|
||||||
link_text = f'{bound_field.label} {_("is not empty")}'
|
link_text = f'{bound_field.label} {_("is not empty")}'
|
||||||
elif modifier != 'exact' and (label := lookup_labels.get(modifier)):
|
elif lookup_label:
|
||||||
link_text = f'{bound_field.label} {label}: {display_value}'
|
link_text = f'{bound_field.label} {lookup_label}: {display_value}'
|
||||||
else:
|
else:
|
||||||
link_text = f'{bound_field.label}: {display_value}'
|
link_text = f'{bound_field.label}: {display_value}'
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user