1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

#11516: Tweak fix to ensure proper highlighting

This commit is contained in:
jeremystretch
2023-01-20 13:43:47 -05:00
parent fcd0481b09
commit 5911041777
2 changed files with 20 additions and 3 deletions

View File

@@ -1,3 +1,4 @@
import re
from collections import namedtuple
from django.conf import settings
@@ -160,7 +161,13 @@ class SearchView(View):
lookup=lookup
)
if form.cleaned_data['lookup'] != LookupTypes.EXACT:
# If performing a regex search, pass the highlight value as a compiled pattern
if form.cleaned_data['lookup'] == LookupTypes.REGEX:
try:
highlight = re.compile(f"({form.cleaned_data['q']})", flags=re.IGNORECASE)
except re.error:
pass
elif form.cleaned_data['lookup'] != LookupTypes.EXACT:
highlight = form.cleaned_data['q']
table = SearchTable(results, highlight=highlight)