From 42df6be6040c492b5b6e3cf2f6a494b200e54637 Mon Sep 17 00:00:00 2001 From: Jason Novinger Date: Mon, 24 Nov 2025 16:11:12 -0600 Subject: [PATCH] Fix applied_filters template tag to use field-type-specific lookup labelsresolves E.g. resolves gt="after" for dates vs "greater than" for numbers --- netbox/utilities/forms/mixins.py | 4 ++-- netbox/utilities/templatetags/helpers.py | 24 +++++++++++++++--------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/netbox/utilities/forms/mixins.py b/netbox/utilities/forms/mixins.py index 751323c61..315184325 100644 --- a/netbox/utilities/forms/mixins.py +++ b/netbox/utilities/forms/mixins.py @@ -208,8 +208,8 @@ class FilterModifierMixin: Returns an empty list for fields that should not be enhanced. """ for field_class in field.__class__.__mro__: - if field_class in FORM_FIELD_LOOKUPS: - return FORM_FIELD_LOOKUPS[field_class] + if field_lookups := FORM_FIELD_LOOKUPS.get(field_class): + return field_lookups return [] diff --git a/netbox/utilities/templatetags/helpers.py b/netbox/utilities/templatetags/helpers.py index d4da65cca..19318111e 100644 --- a/netbox/utilities/templatetags/helpers.py +++ b/netbox/utilities/templatetags/helpers.py @@ -414,13 +414,6 @@ def applied_filters(context, model, form, query_params): user = context['request'].user 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 = [] for filter_name in form.changed_data: if filter_name not in form.cleaned_data: @@ -459,14 +452,27 @@ def applied_filters(context, model, form, query_params): # Get display value 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) if modifier == 'empty': if display_value.lower() in ('true', '1'): link_text = f'{bound_field.label} {_("is empty")}' else: link_text = f'{bound_field.label} {_("is not empty")}' - elif modifier != 'exact' and (label := lookup_labels.get(modifier)): - link_text = f'{bound_field.label} {label}: {display_value}' + elif lookup_label: + link_text = f'{bound_field.label} {lookup_label}: {display_value}' else: link_text = f'{bound_field.label}: {display_value}'