From 728a77a526f9606d9c55fb71e5727ba7202b3489 Mon Sep 17 00:00:00 2001 From: John Carroll Date: Mon, 11 Dec 2023 18:25:19 -0500 Subject: [PATCH 1/2] filter to strip `FEC | ` prefix and ` - FEC.gov` suffix from search.gov search result title --- fec/home/templatetags/filters.py | 15 +++++++++++++++ fec/search/templates/search/search.html | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/fec/home/templatetags/filters.py b/fec/home/templatetags/filters.py index d33ae4f3bf..2dba5d8b2b 100644 --- a/fec/home/templatetags/filters.py +++ b/fec/home/templatetags/filters.py @@ -66,13 +66,26 @@ def web_app_url(path): return "{}{}".format(settings.FEC_APP_URL, path) +@register.filter(name='remove_title_pre_suf_fix') +def remove_title_pre_suf_fix(str): + """ + Removes 'FEC | ' prefix and ' - FEC.gov' suffix' from search.gov search result title + """ + str = re.sub(r'(^FEC \| | - FEC\.gov$)', '', str) + return str + + @register.filter() def highlight_matches(text): """ Replaces the highlight markers with span tags for Search.gov website search results. Because format_html uses str.format, remove { and } because they are special characters. """ + + #text = remove_result_pre_suf_fix(text) cleaned_text = text.replace("{", "").replace("}", "") + + highlighted_text = cleaned_text.replace( "\ue000", '' ).replace("\ue001", "") @@ -189,3 +202,5 @@ def get_file_type(value): file_type = "EXCEL" if xl else file_extension return file_type + + diff --git a/fec/search/templates/search/search.html b/fec/search/templates/search/search.html index 8a8e716188..0be75d5867 100644 --- a/fec/search/templates/search/search.html +++ b/fec/search/templates/search/search.html @@ -162,7 +162,7 @@

Other pages

{% for result in results.site.results %}
  • - {{ result.title | highlight_matches }} + {{ result.title | remove_title_pre_suf_fix | highlight_matches }}

    {{ result.url }}

    {{ result.snippet | highlight_matches }}

    From 5144da14936367c36e785717d601004d757bbf87 Mon Sep 17 00:00:00 2001 From: John Carroll Date: Mon, 11 Dec 2023 22:00:28 -0500 Subject: [PATCH 2/2] rm commented text --- fec/home/templatetags/filters.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/fec/home/templatetags/filters.py b/fec/home/templatetags/filters.py index 2dba5d8b2b..6c65f42a67 100644 --- a/fec/home/templatetags/filters.py +++ b/fec/home/templatetags/filters.py @@ -81,11 +81,7 @@ def highlight_matches(text): Replaces the highlight markers with span tags for Search.gov website search results. Because format_html uses str.format, remove { and } because they are special characters. """ - - #text = remove_result_pre_suf_fix(text) cleaned_text = text.replace("{", "").replace("}", "") - - highlighted_text = cleaned_text.replace( "\ue000", '' ).replace("\ue001", "")