From 968f4f716b41a2989cfff16e6a10fab9a2e08c6b Mon Sep 17 00:00:00 2001 From: Muhammad Adeel Tajamul <77053848+muhammadadeeltajamul@users.noreply.github.com> Date: Mon, 21 Oct 2024 16:04:44 +0500 Subject: [PATCH] feat: removed styling from course update notification (#35680) --- .../contentstore/tests/test_utils.py | 15 ++++++++++++++- cms/djangoapps/contentstore/utils.py | 19 +++---------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/cms/djangoapps/contentstore/tests/test_utils.py b/cms/djangoapps/contentstore/tests/test_utils.py index 9c478ddfe5d7..2c5be351fc50 100644 --- a/cms/djangoapps/contentstore/tests/test_utils.py +++ b/cms/djangoapps/contentstore/tests/test_utils.py @@ -960,4 +960,17 @@ def test_course_update_notification_sent(self): send_course_update_notification(self.course.id, content, self.user) assert Notification.objects.all().count() == 1 notification = Notification.objects.first() - assert notification.content == "

content

" + assert notification.content == "

content

" + + def test_if_content_is_plain_text(self): + """ + Test that the course_update notification is sent. + """ + user = UserFactory() + CourseEnrollment.enroll(user=user, course_key=self.course.id) + assert Notification.objects.all().count() == 0 + content = "

content

Sub content

heading

" + send_course_update_notification(self.course.id, content, self.user) + assert Notification.objects.all().count() == 1 + notification = Notification.objects.first() + assert notification.content == "

content Sub content heading

" diff --git a/cms/djangoapps/contentstore/utils.py b/cms/djangoapps/contentstore/utils.py index aeb3e975d1e2..940137b1d5d1 100644 --- a/cms/djangoapps/contentstore/utils.py +++ b/cms/djangoapps/contentstore/utils.py @@ -2248,22 +2248,9 @@ def clean_html_body(html_body): Get html body, remove tags and limit to 500 characters """ html_body = BeautifulSoup(Truncator(html_body).chars(500, html=True), 'html.parser') - - tags_to_remove = [ - "a", "link", # Link Tags - "img", "picture", "source", # Image Tags - "video", "track", # Video Tags - "audio", # Audio Tags - "embed", "object", "iframe", # Embedded Content - "script" - ] - - # Remove the specified tags while keeping their content - for tag in tags_to_remove: - for match in html_body.find_all(tag): - match.unwrap() - - return str(html_body) + text_content = html_body.get_text(separator=" ").strip() + text_content = text_content.replace('\n', '').replace('\r', '') + return text_content def send_course_update_notification(course_key, content, user):