Merge pull request #30406 from openedx/feat--change-default-title-for-text-xblock-to-be-'Text'

Feat  change default title for text xblock to be 'text'
This commit is contained in:
Raymond Zhou
2022-05-31 09:35:33 -07:00
committed by GitHub
4 changed files with 48 additions and 3 deletions

View File

@@ -736,3 +736,34 @@ class ValidateCourseOlxTests(CourseTestCase):
ignore=ignore,
allowed_xblocks=allowed_xblocks
)
class DetermineLabelTestCase(TestCase):
"""Tests for xblock Title quirks"""
def validate_html_replaced_with_text(self):
"""
Tests that display names for "html" xblocks are repleaced 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, display_name)
def validate_set_titles_not_replaced(self):
"""
Tests that display names for "html" xblocks are not repleaced 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, display_name)
def validate_non_html_blocks_titles_not_replaced(self):
"""
Tests that display names for non-"html" xblocks are not repleaced 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, display_name)

View File

@@ -703,6 +703,17 @@ 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.
"""
label = display_name
if block_type == 'html':
label = _("Text")
return label
@contextmanager
def translation_language(language):
"""Context manager to override the translation language for the scope

View File

@@ -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