diff --git a/fec/data/templatetags/filters.py b/fec/data/templatetags/filters.py
index db7d9be048..eb05abd615 100644
--- a/fec/data/templatetags/filters.py
+++ b/fec/data/templatetags/filters.py
@@ -4,6 +4,7 @@
import re
from dateutil.parser import parse as parse_date
+from difflib import SequenceMatcher
from django.conf import settings
from django_jinja import library
@@ -164,6 +165,43 @@ def filesize(value):
return '%d %s' % (value, units[unit])
+@library.filter
+def compare(string, string_1):
+ """Compares two strings to determine if they are nearly identical or semantically similar.
+ Returns False if `string` is >= than 50% similar to `string_1`. Else returns True.
+ Uses difflib.SequenceMatcher: https://docs.python.org/3/library/difflib.html
+ """
+
+ # Calculate the similarity ratio
+ similarity_ratio = SequenceMatcher(None, string, string_1).ratio()
+
+ # Define a threshold for redundancy (e.g., 50% similar)
+ threshold = .5
+
+ if similarity_ratio >= threshold:
+ return False
+
+ else:
+ return True
+
+
+@library.filter
+def compare_commenter(string, string_1):
+ """Convert `string_1` from "LastName, FirstName" format to "FirstName LastName"
+ Returns False if `converted_string_1` is in `string`.
+ Returns False if `string` == 'Comment'.
+ Else returns True.
+ """
+
+ # Convert name from "LastName, FirstName" format to "FirstName LastName"
+ converted_string_1 = ' '.join(reversed(string_1.split(', ')))
+
+ if converted_string_1 in string or string == 'Comment':
+ return False
+ else:
+ return True
+
+
@library.global_function
def path_for_css(key):
"""Looks up the hashed asset key in rev-manifest-css.json
diff --git a/fec/legal/templates/rulemaking.jinja b/fec/legal/templates/rulemaking.jinja
index c0ad863c57..a62577b424 100644
--- a/fec/legal/templates/rulemaking.jinja
+++ b/fec/legal/templates/rulemaking.jinja
@@ -71,16 +71,15 @@
-
{%- if docL1.url -%}
- {{ docL1.label }}
+ {{ docL1.label }}
{%- else -%}
- {{ docL1.label }}
+ {{ docL1.label }}
{%- endif -%}
- {%- if docL1.doc_description and 'pdf' not in docL1.doc_description.lower() -%}
-
{{ docL1.doc_description }}
+ {%- if docL1.doc_description and 'pdf' not in docL1.doc_description.lower() and docL1.doc_description | compare(docL1.label) -%}
+
{{ docL1.doc_description }}
{%- endif -%}
{%- if docL1.doc_entities -%}
-
{%- for entity in docL1.doc_entities -%}
- {{ entity.name }}, {{ entity.role }}
{%- endfor -%}
@@ -105,7 +104,7 @@
{% if (doc.label == 'Comments' or doc.label == 'Hearing Schedule') and doc.doc_entities %}
{% if doc.label == 'Hearing Schedule' %}
- - {{ doc.label }}
+ - {{ doc.label }}
{% for entity in doc.doc_entities %}
- {{ entity.name }}, {{ entity.role }}
{% endfor %}
@@ -114,16 +113,21 @@
{% if doc.commenters|length == 1 %}
{# Single commenter: show commenter name #}
-
- {{ doc.commenters[0].name }} | {{ doc.commenters[0].role }}
- {% if doc.doc_description and 'pdf' not in doc.doc_description.lower() %}
{{ doc.doc_description }}{% endif %}
+ {{ doc.commenters[0].name }} | {{ doc.commenters[0].role }}
+ {% if doc.doc_description and 'pdf' not in doc.doc_description.lower() and doc.doc_description | compare_commenter(doc.commenters[0].name) %}
+
{{ doc.doc_description }}
+ {% endif %}
- {% for entity in doc.doc_entities %}
+ {% for entity in doc.doc_entities if entity.role != 'Commenter' %}
- {{ entity.name }}, {{ entity.role }}
{% endfor %}
{% else %}
{# Multiple commenters: show "Joint comment" #}
- Joint comment
- {% if doc.doc_description and 'pdf' not in doc.doc_description.lower() %}
{{ doc.doc_description }}{% endif %}
+ {% if doc.doc_description and 'pdf' not in doc.doc_description.lower() %}
+
{{ doc.doc_description }}
+ {% endif %}
+
{% for entity in doc.doc_entities %}
- {{ entity.name }}, {{ entity.role }}
{% endfor %}
@@ -131,8 +135,8 @@
{% endif %}
{% else %}
{{ doc.label }}
- {% if doc.doc_description and 'pdf' not in doc.doc_description.lower() %}
-
{{ doc.doc_description }}
+ {% if doc.doc_description and 'pdf' not in doc.doc_description.lower() and doc.doc_description | compare(doc.label) %}
+
{{ doc.doc_description }}
{% endif %}
{% endif %}