mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-13 03:49:36 -06:00
Address PR feedback: Refactor applied_filters to use FORM_FIELD_LOOKUPS
This commit is contained in:
parent
560dcb6af1
commit
562334eac8
@ -9,6 +9,7 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
|
|
||||||
from core.models import ObjectType
|
from core.models import ObjectType
|
||||||
from utilities.forms import get_selected_values, TableConfigForm
|
from utilities.forms import get_selected_values, TableConfigForm
|
||||||
|
from utilities.forms.mixins import FORM_FIELD_LOOKUPS
|
||||||
from utilities.views import get_viewname, get_action_url
|
from utilities.views import get_viewname, get_action_url
|
||||||
from netbox.settings import DISK_BASE_UNIT, RAM_BASE_UNIT
|
from netbox.settings import DISK_BASE_UNIT, RAM_BASE_UNIT
|
||||||
|
|
||||||
@ -413,6 +414,13 @@ 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:
|
||||||
@ -457,23 +465,8 @@ def applied_filters(context, model, form, query_params):
|
|||||||
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")}'
|
||||||
else:
|
elif modifier != 'exact' and (label := lookup_labels.get(modifier)):
|
||||||
# Add friendly lookup label for other modifier-enhanced fields
|
link_text = f'{bound_field.label} {label}: {display_value}'
|
||||||
lookup_labels = {
|
|
||||||
'n': _('is not'),
|
|
||||||
'ic': _('contains'),
|
|
||||||
'isw': _('starts with'),
|
|
||||||
'iew': _('ends with'),
|
|
||||||
'ie': _('equals (case-insensitive)'),
|
|
||||||
'regex': _('matches pattern'),
|
|
||||||
'iregex': _('matches pattern (case-insensitive)'),
|
|
||||||
'gt': _('>'),
|
|
||||||
'gte': _('≥'),
|
|
||||||
'lt': _('<'),
|
|
||||||
'lte': _('≤'),
|
|
||||||
}
|
|
||||||
if modifier != 'exact' and modifier in lookup_labels:
|
|
||||||
link_text = f'{bound_field.label} {lookup_labels[modifier]}: {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