feat: Prevent empty wrapper divs for about sections with no content (#37551)
This commit is contained in:
@@ -53,6 +53,7 @@ from lms.djangoapps.courseware.exceptions import CourseAccessRedirect, CourseRun
|
||||
from lms.djangoapps.courseware.masquerade import check_content_start_date_for_masquerade_user
|
||||
from lms.djangoapps.courseware.model_data import FieldDataCache
|
||||
from lms.djangoapps.courseware.block_render import get_block
|
||||
from lms.djangoapps.courseware.utils import is_empty_html
|
||||
from lms.djangoapps.grades.api import CourseGradeFactory
|
||||
from lms.djangoapps.survey.utils import SurveyRequiredAccessError, check_survey_required_and_unanswered
|
||||
from openedx.core.djangoapps.content.block_structure.api import get_block_structure_manager
|
||||
@@ -418,7 +419,10 @@ def get_course_about_section(request, course, section_key):
|
||||
|
||||
if about_block is not None:
|
||||
try:
|
||||
html = about_block.render(STUDENT_VIEW).content
|
||||
# Only render XBlock if content exists to avoid generating empty wrapper divs
|
||||
content = about_block.data
|
||||
if not is_empty_html(content):
|
||||
html = about_block.render(STUDENT_VIEW).content
|
||||
except Exception: # pylint: disable=broad-except
|
||||
html = render_to_string('courseware/error-message.html', None)
|
||||
log.exception(
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import datetime
|
||||
import hashlib
|
||||
import logging
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from django.conf import settings
|
||||
from django.http import HttpResponse, HttpResponseBadRequest
|
||||
@@ -229,3 +230,16 @@ def _use_new_financial_assistance_flow(course_id):
|
||||
):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def is_empty_html(html_content):
|
||||
"""
|
||||
Check if HTML content is effectively empty.
|
||||
"""
|
||||
if not html_content:
|
||||
return True
|
||||
|
||||
soup = BeautifulSoup(html_content, 'html.parser')
|
||||
text = soup.get_text(strip=True)
|
||||
|
||||
return not text
|
||||
|
||||
Reference in New Issue
Block a user