feat: change text xblock title to 'Text' v2 (#30578)
This commit is contained in:
@@ -736,3 +736,43 @@ class ValidateCourseOlxTests(CourseTestCase):
|
||||
ignore=ignore,
|
||||
allowed_xblocks=allowed_xblocks
|
||||
)
|
||||
|
||||
|
||||
class DetermineLabelTests(TestCase):
|
||||
"""Tests for xblock Title"""
|
||||
|
||||
def test_html_replaced_with_text_for_none(self):
|
||||
"""
|
||||
Tests that display names for "html" xblocks are replaced with "Text" when the display name is otherwise unset.
|
||||
"""
|
||||
display_name = None
|
||||
block_type = "html"
|
||||
result = utils.determine_label(display_name, block_type)
|
||||
self.assertEqual(result, "Text")
|
||||
|
||||
def test_html_replaced_with_text_for_empty(self):
|
||||
"""
|
||||
Tests that display names for "html" xblocks are replaced with "Text" when the display name is empty.
|
||||
"""
|
||||
display_name = ""
|
||||
block_type = "html"
|
||||
result = utils.determine_label(display_name, block_type)
|
||||
self.assertEqual(result, "Text")
|
||||
|
||||
def test_set_titles_not_replaced(self):
|
||||
"""
|
||||
Tests that display names for "html" xblocks are not replaced with "Text" when the display name is set.
|
||||
"""
|
||||
display_name = "Something"
|
||||
block_type = "html"
|
||||
result = utils.determine_label(display_name, block_type)
|
||||
self.assertEqual(result, "Something")
|
||||
|
||||
def test_non_html_blocks_titles_not_replaced(self):
|
||||
"""
|
||||
Tests that display names for non-"html" xblocks are not replaced with "Text" when the display name is set.
|
||||
"""
|
||||
display_name = None
|
||||
block_type = "something else"
|
||||
result = utils.determine_label(display_name, block_type)
|
||||
self.assertEqual(result, "something else")
|
||||
|
||||
@@ -703,6 +703,20 @@ def get_sibling_urls(subsection, unit_location): # pylint: disable=too-many-s
|
||||
return prev_url, next_url
|
||||
|
||||
|
||||
def determine_label(display_name, block_type):
|
||||
"""
|
||||
Returns the name of the xblock to display in studio.
|
||||
Please see TNL-9838.
|
||||
"""
|
||||
if display_name in {"", None}:
|
||||
if block_type == 'html':
|
||||
return _("Text")
|
||||
else:
|
||||
return block_type
|
||||
else:
|
||||
return display_name
|
||||
|
||||
|
||||
@contextmanager
|
||||
def translation_language(language):
|
||||
"""Context manager to override the translation language for the scope
|
||||
|
||||
@@ -427,13 +427,16 @@ def xblock_view_handler(request, usage_key_string, view_name):
|
||||
|
||||
# Note that the container view recursively adds headers into the preview fragment,
|
||||
# so only the "Pages" view requires that this extra wrapper be included.
|
||||
display_label = xblock.display_name or xblock.scope_ids.block_type
|
||||
if not xblock.display_name and xblock.scope_ids.block_type == 'html':
|
||||
display_label = _("Text")
|
||||
if is_pages_view:
|
||||
fragment.content = render_to_string('component.html', {
|
||||
'xblock_context': context,
|
||||
'xblock': xblock,
|
||||
'locator': usage_key,
|
||||
'preview': fragment.content,
|
||||
'label': xblock.display_name or xblock.scope_ids.block_type,
|
||||
'label': display_label,
|
||||
})
|
||||
else:
|
||||
raise Http404
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<%!
|
||||
from django.utils.translation import gettext as _
|
||||
from cms.djangoapps.contentstore.views.helpers import xblock_studio_url
|
||||
from cms.djangoapps.contentstore.utils import is_visible_to_specific_partition_groups, get_editor_page_base_url
|
||||
from cms.djangoapps.contentstore.utils import is_visible_to_specific_partition_groups, get_editor_page_base_url, determine_label
|
||||
from lms.lib.utils import is_unit
|
||||
from openedx.core.djangolib.js_utils import (
|
||||
dump_js_escaped_json, js_escaped_string
|
||||
@@ -17,7 +17,7 @@ xblock_url = xblock_studio_url(xblock)
|
||||
show_inline = xblock.has_children and not xblock_url
|
||||
section_class = "level-nesting" if show_inline else "level-element"
|
||||
collapsible_class = "is-collapsible" if xblock.has_children else ""
|
||||
label = xblock.display_name_with_default or xblock.scope_ids.block_type
|
||||
label = determine_label(xblock.display_name_with_default, xblock.scope_ids.block_type)
|
||||
messages = xblock.validate().to_json()
|
||||
block_is_unit = is_unit(xblock)
|
||||
%>
|
||||
|
||||
Reference in New Issue
Block a user