From cdfee19ba3d9934949504477faf35b7a243814fe Mon Sep 17 00:00:00 2001 From: bszabo Date: Mon, 21 Aug 2023 16:32:58 -0400 Subject: [PATCH] Revert "fix: refactor MakoService to allow specifying namespace per template (#33061)" (#33070) This reverts commit d60cdc2305fc7ebb99fbffa5fad535a91f9f0be2. --- .../contentstore/views/tests/test_preview.py | 2 +- cms/lib/xblock/authoring_mixin.py | 2 +- common/djangoapps/edxmako/services.py | 48 +------------------ .../courseware/tests/test_video_mongo.py | 22 ++++----- .../library-block-author-preview-header.html | 0 xmodule/annotatable_block.py | 4 +- xmodule/capa_block.py | 8 ++-- xmodule/conditional_block.py | 6 +-- xmodule/discussion_block.py | 5 +- xmodule/error_block.py | 2 +- xmodule/html_block.py | 4 +- xmodule/library_content_block.py | 6 +-- xmodule/library_root_xblock.py | 3 +- xmodule/lti_block.py | 6 +-- xmodule/poll_block.py | 2 +- xmodule/seq_block.py | 4 +- xmodule/split_test_block.py | 8 ++-- xmodule/studio_editable.py | 5 +- xmodule/template_block.py | 2 +- xmodule/tests/helpers.py | 12 ----- xmodule/tests/test_conditional.py | 4 +- xmodule/tests/test_html_block.py | 2 +- xmodule/vertical_block.py | 3 +- xmodule/video_block/video_block.py | 4 +- xmodule/word_cloud_block.py | 4 +- 25 files changed, 55 insertions(+), 113 deletions(-) rename {cms => lms}/templates/library-block-author-preview-header.html (100%) diff --git a/cms/djangoapps/contentstore/views/tests/test_preview.py b/cms/djangoapps/contentstore/views/tests/test_preview.py index b97a1a41105..0f6786ca623 100644 --- a/cms/djangoapps/contentstore/views/tests/test_preview.py +++ b/cms/djangoapps/contentstore/views/tests/test_preview.py @@ -186,7 +186,7 @@ def student_view(self, context): Renders the output that a student will see. """ fragment = Fragment() - fragment.add_content(self.runtime.service(self, 'mako').render_lms_template('edxmako.html', context)) + fragment.add_content(self.runtime.service(self, 'mako').render_template('edxmako.html', context)) return fragment diff --git a/cms/lib/xblock/authoring_mixin.py b/cms/lib/xblock/authoring_mixin.py index a3d3b3298ce..bb6b742f44c 100644 --- a/cms/lib/xblock/authoring_mixin.py +++ b/cms/lib/xblock/authoring_mixin.py @@ -37,7 +37,7 @@ def visibility_view(self, _context=None): """ fragment = Fragment() from cms.djangoapps.contentstore.utils import reverse_course_url - fragment.add_content(self.runtime.service(self, 'mako').render_cms_template('visibility_editor.html', { + fragment.add_content(self.runtime.service(self, 'mako').render_template('visibility_editor.html', { 'xblock': self, 'manage_groups_url': reverse_course_url('group_configurations_list_handler', self.location.course_key), })) diff --git a/common/djangoapps/edxmako/services.py b/common/djangoapps/edxmako/services.py index d300e32cf75..6ee2b096d63 100644 --- a/common/djangoapps/edxmako/services.py +++ b/common/djangoapps/edxmako/services.py @@ -1,23 +1,10 @@ """ Supports rendering an XBlock to HTML using mako templates. """ -from django.template import engines -from django.template.utils import InvalidTemplateEngineError + from xblock.reference.plugins import Service from common.djangoapps.edxmako.shortcuts import render_to_string -from common.djangoapps.edxmako import Engines - -try: - engines[Engines.PREVIEW] -except InvalidTemplateEngineError: - # We are running in the CMS: - lms_mako_namespace = "main" - cms_mako_namespace = None -else: - # We are running in the LMS: - lms_mako_namespace = "lms.main" - cms_mako_namespace = "main" class MakoService(Service): @@ -34,41 +21,10 @@ def __init__( **kwargs ): super().__init__(**kwargs) - # Set the "default" namespace prefix, in case it's not specified when render_template() is called. self.namespace_prefix = namespace_prefix def render_template(self, template_file, dictionary, namespace='main'): """ - DEPRECATED. Takes (template_file, dictionary) and returns rendered HTML. - - Use render_lms_template or render_cms_template instead. Or better yet, - don't use mako templates at all. React or django templates are much - safer. + Takes (template_file, dictionary) and returns rendered HTML. """ return render_to_string(template_file, dictionary, namespace=self.namespace_prefix + namespace) - - def render_lms_template(self, template_file, dictionary): - """ - Render a template which is found in one of the LMS edx-platform template - dirs. (lms.envs.common.MAKO_TEMPLATE_DIRS_BASE) - - Templates which are in these dirs will only work with this function: - edx-platform/lms/templates/ - edx-platform/xmodule/capa/templates/ - openedx/features/course_experience/templates - """ - return render_to_string(template_file, dictionary, namespace=lms_mako_namespace) - - def render_cms_template(self, template_file, dictionary): - """ - Render a template which is found in one of the CMS edx-platform template - dirs. (cms.envs.common.MAKO_TEMPLATE_DIRS_BASE) - - Templates which are in these dirs will only work with this function: - edx-platform/cms/templates/ - common/static/ - openedx/features/course_experience/templates - """ - if cms_mako_namespace is None: - raise RuntimeError("Cannot access CMS templates from the LMS") - return render_to_string(template_file, dictionary, namespace=cms_mako_namespace) diff --git a/lms/djangoapps/courseware/tests/test_video_mongo.py b/lms/djangoapps/courseware/tests/test_video_mongo.py index 452962c06f5..a1a01dcfd71 100644 --- a/lms/djangoapps/courseware/tests/test_video_mongo.py +++ b/lms/djangoapps/courseware/tests/test_video_mongo.py @@ -148,7 +148,7 @@ def test_video_constructor(self): mako_service = self.block.runtime.service(self.block, 'mako') assert get_context_dict_from_string(context) ==\ - get_context_dict_from_string(mako_service.render_lms_template('video.html', expected_context)) + get_context_dict_from_string(mako_service.render_template('video.html', expected_context)) class TestVideoNonYouTube(TestVideo): # pylint: disable=test-inherits-tests @@ -233,7 +233,7 @@ def test_video_constructor(self): mako_service = self.block.runtime.service(self.block, 'mako') expected_result = get_context_dict_from_string( - mako_service.render_lms_template('video.html', expected_context) + mako_service.render_template('video.html', expected_context) ) assert get_context_dict_from_string(context) == expected_result assert expected_result['download_video_link'] == 'example.mp4' @@ -506,7 +506,7 @@ def test_get_html_track(self): mako_service = self.block.runtime.service(self.block, 'mako') assert get_context_dict_from_string(context) ==\ - get_context_dict_from_string(mako_service.render_lms_template('video.html', expected_context)) + get_context_dict_from_string(mako_service.render_template('video.html', expected_context)) def test_get_html_source(self): # lint-amnesty, pylint: disable=invalid-name, redefined-outer-name @@ -620,7 +620,7 @@ def test_get_html_source(self): mako_service = self.block.runtime.service(self.block, 'mako') assert get_context_dict_from_string(context) ==\ - get_context_dict_from_string(mako_service.render_lms_template('video.html', expected_context)) + get_context_dict_from_string(mako_service.render_template('video.html', expected_context)) def test_get_html_with_non_existent_edx_video_id(self): """ @@ -766,7 +766,7 @@ def test_get_html_with_mocked_edx_video_id(self): mako_service = self.block.runtime.service(self.block, 'mako') assert get_context_dict_from_string(context) ==\ - get_context_dict_from_string(mako_service.render_lms_template('video.html', expected_context)) + get_context_dict_from_string(mako_service.render_template('video.html', expected_context)) def test_get_html_with_existing_edx_video_id(self): """ @@ -794,7 +794,7 @@ def test_get_html_with_existing_edx_video_id(self): context, expected_context = self.helper_get_html_with_edx_video_id(data) mako_service = self.block.runtime.service(self.block, 'mako') assert get_context_dict_from_string(context) ==\ - get_context_dict_from_string(mako_service.render_lms_template('video.html', expected_context)) + get_context_dict_from_string(mako_service.render_template('video.html', expected_context)) def test_get_html_with_existing_unstripped_edx_video_id(self): """ @@ -825,7 +825,7 @@ def test_get_html_with_existing_unstripped_edx_video_id(self): mako_service = self.block.runtime.service(self.block, 'mako') assert get_context_dict_from_string(context) ==\ - get_context_dict_from_string(mako_service.render_lms_template('video.html', expected_context)) + get_context_dict_from_string(mako_service.render_template('video.html', expected_context)) def encode_and_create_video(self, edx_video_id): """ @@ -1050,7 +1050,7 @@ def side_effect(*args, **kwargs): # lint-amnesty, pylint: disable=unused-argume mako_service = self.block.runtime.service(self.block, 'mako') assert get_context_dict_from_string(context) ==\ - get_context_dict_from_string(mako_service.render_lms_template('video.html', expected_context)) + get_context_dict_from_string(mako_service.render_template('video.html', expected_context)) # pylint: disable=invalid-name def test_get_html_cdn_source_external_video(self): @@ -1156,7 +1156,7 @@ def test_get_html_cdn_source_external_video(self): mako_service = self.block.runtime.service(self.block, 'mako') assert get_context_dict_from_string(context) ==\ - get_context_dict_from_string(mako_service.render_lms_template('video.html', expected_context)) + get_context_dict_from_string(mako_service.render_template('video.html', expected_context)) @ddt.data( (True, ['youtube', 'desktop_webm', 'desktop_mp4', 'hls']), @@ -2409,7 +2409,7 @@ def test_bumper_metadata(self, get_url_for_profiles, get_bumper_settings, is_bum } mako_service = self.block.runtime.service(self.block, 'mako') - expected_content = mako_service.render_lms_template('video.html', expected_context) + expected_content = mako_service.render_template('video.html', expected_context) assert get_context_dict_from_string(content) == get_context_dict_from_string(expected_content) @@ -2506,7 +2506,7 @@ def assert_content_matches_expectations(self, autoadvanceenabled_must_be, autoad mako_service = self.block.runtime.service(self.block, 'mako') with override_settings(FEATURES=self.FEATURES): - expected_content = mako_service.render_lms_template('video.html', expected_context) + expected_content = mako_service.render_template('video.html', expected_context) assert get_context_dict_from_string(content) == get_context_dict_from_string(expected_content) diff --git a/cms/templates/library-block-author-preview-header.html b/lms/templates/library-block-author-preview-header.html similarity index 100% rename from cms/templates/library-block-author-preview-header.html rename to lms/templates/library-block-author-preview-header.html diff --git a/xmodule/annotatable_block.py b/xmodule/annotatable_block.py index e41e2b17a52..95f68d4370b 100644 --- a/xmodule/annotatable_block.py +++ b/xmodule/annotatable_block.py @@ -172,7 +172,7 @@ def get_html(self): 'content_html': self._render_content() } - return self.runtime.service(self, 'mako').render_lms_template('annotatable.html', context) + return self.runtime.service(self, 'mako').render_template('annotatable.html', context) def student_view(self, context): # lint-amnesty, pylint: disable=unused-argument """ @@ -191,7 +191,7 @@ def studio_view(self, _context): Return the studio view. """ fragment = Fragment( - self.runtime.service(self, 'mako').render_cms_template(self.mako_template, self.get_context()) + self.runtime.service(self, 'mako').render_template(self.mako_template, self.get_context()) ) add_sass_to_fragment(fragment, 'AnnotatableBlockEditor.scss') add_webpack_js_to_fragment(fragment, 'AnnotatableBlockEditor') diff --git a/xmodule/capa_block.py b/xmodule/capa_block.py index 94d4b2a61f4..c9916968887 100644 --- a/xmodule/capa_block.py +++ b/xmodule/capa_block.py @@ -356,7 +356,7 @@ def studio_view(self, _context): Return the studio view. """ fragment = Fragment( - self.runtime.service(self, 'mako').render_cms_template(self.mako_template, self.get_context()) + self.runtime.service(self, 'mako').render_template(self.mako_template, self.get_context()) ) add_sass_to_fragment(fragment, 'ProblemBlockEditor.scss') add_webpack_js_to_fragment(fragment, 'ProblemBlockEditor') @@ -898,7 +898,7 @@ def get_html(self): """ curr_score, total_possible = self.get_display_progress() - return self.runtime.service(self, 'mako').render_lms_template('problem_ajax.html', { + return self.runtime.service(self, 'mako').render_template('problem_ajax.html', { 'element_id': self.location.html_id(), 'id': str(self.location), 'ajax_url': self.ajax_url, @@ -1247,7 +1247,7 @@ def get_problem_html(self, encapsulate=True, submit_notification=False): 'submit_disabled_cta': submit_disabled_ctas[0] if submit_disabled_ctas else None, } - html = self.runtime.service(self, 'mako').render_lms_template('problem.html', context) + html = self.runtime.service(self, 'mako').render_template('problem.html', context) if encapsulate: html = HTML('
{html}
').format( @@ -1548,7 +1548,7 @@ def get_answer(self, _data): return { 'answers': new_answers, - 'correct_status_html': self.runtime.service(self, 'mako').render_lms_template( + 'correct_status_html': self.runtime.service(self, 'mako').render_template( 'status_span.html', {'status': Status('correct', self.runtime.service(self, "i18n").gettext)} ) diff --git a/xmodule/conditional_block.py b/xmodule/conditional_block.py index 78a5b8c1c1c..03662deb01e 100644 --- a/xmodule/conditional_block.py +++ b/xmodule/conditional_block.py @@ -223,7 +223,7 @@ def student_view(self, _context): def get_html(self): required_html_ids = [block.location.html_id() for block in self.get_required_blocks] - return self.runtime.service(self, 'mako').render_lms_template('conditional_ajax.html', { + return self.runtime.service(self, 'mako').render_template('conditional_ajax.html', { 'element_id': self.location.html_id(), 'ajax_url': self.ajax_url, 'depends': ';'.join(required_html_ids) @@ -249,7 +249,7 @@ def studio_view(self, _context): Return the studio view. """ fragment = Fragment( - self.runtime.service(self, 'mako').render_cms_template(self.mako_template, self.get_context()) + self.runtime.service(self, 'mako').render_template(self.mako_template, self.get_context()) ) add_webpack_js_to_fragment(fragment, 'ConditionalBlockEditor') shim_xmodule_js(fragment, self.studio_js_module_name) @@ -262,7 +262,7 @@ def handle_ajax(self, _dispatch, _data): if not self.is_condition_satisfied(): context = {'module': self, 'message': self.conditional_message} - html = self.runtime.service(self, 'mako').render_lms_template('conditional_block.html', context) + html = self.runtime.service(self, 'mako').render_template('conditional_block.html', context) return json.dumps({'fragments': [{'content': html}], 'message': bool(self.conditional_message)}) fragments = [child.render(STUDENT_VIEW).to_dict() for child in self.get_children()] diff --git a/xmodule/discussion_block.py b/xmodule/discussion_block.py index b5c5c01907c..7433b51c9f9 100644 --- a/xmodule/discussion_block.py +++ b/xmodule/discussion_block.py @@ -204,7 +204,7 @@ def student_view(self, context=None): 'login_msg': login_msg, } fragment.add_content( - self.runtime.service(self, 'mako').render_lms_template('discussion/_discussion_inline.html', context) + self.runtime.service(self, 'mako').render_template('discussion/_discussion_inline.html', context) ) fragment.initialize_js('DiscussionInlineBlock') @@ -216,8 +216,7 @@ def author_view(self, context=None): # pylint: disable=unused-argument Renders author view for Studio. """ fragment = Fragment() - # For historic reasons, this template is in the LMS templates folder: - fragment.add_content(self.runtime.service(self, 'mako').render_lms_template( + fragment.add_content(self.runtime.service(self, 'mako').render_template( 'discussion/_discussion_inline_studio.html', { 'discussion_id': self.discussion_id, diff --git a/xmodule/error_block.py b/xmodule/error_block.py index 9ee1d47f671..a3379007e19 100644 --- a/xmodule/error_block.py +++ b/xmodule/error_block.py @@ -60,7 +60,7 @@ def student_view(self, _context): """ Return a fragment that contains the html for the student view. """ - fragment = Fragment(self.runtime.service(self, 'mako').render_lms_template('module-error.html', { + fragment = Fragment(self.runtime.service(self, 'mako').render_template('module-error.html', { 'staff_access': True, 'data': self.contents, 'error': self.error_msg, diff --git a/xmodule/html_block.py b/xmodule/html_block.py index 6c883e1322d..688e515c80e 100644 --- a/xmodule/html_block.py +++ b/xmodule/html_block.py @@ -134,7 +134,7 @@ def studio_view(self, _context): Return the studio view. """ fragment = Fragment( - self.runtime.service(self, 'mako').render_cms_template(self.mako_template, self.get_context()) + self.runtime.service(self, 'mako').render_template(self.mako_template, self.get_context()) ) add_sass_to_fragment(fragment, 'HtmlBlockEditor.scss') add_webpack_js_to_fragment(fragment, 'HtmlBlockEditor') @@ -463,7 +463,7 @@ def get_html(self): 'visible_updates': course_updates[:3], 'hidden_updates': course_updates[3:], } - return self.runtime.service(self, 'mako').render_lms_template( + return self.runtime.service(self, 'mako').render_template( f"{self.TEMPLATE_DIR}/course_updates.html", context, ) diff --git a/xmodule/library_content_block.py b/xmodule/library_content_block.py index dd8b7311273..047d36abca5 100644 --- a/xmodule/library_content_block.py +++ b/xmodule/library_content_block.py @@ -391,7 +391,7 @@ def student_view(self, context): # lint-amnesty, pylint: disable=missing-functi 'content': rendered_child.content, }) - fragment.add_content(self.runtime.service(self, 'mako').render_lms_template('vert_module.html', { + fragment.add_content(self.runtime.service(self, 'mako').render_template('vert_module.html', { 'items': contents, 'xblock_context': context, 'show_bookmark_button': False, @@ -421,7 +421,7 @@ def author_view(self, context): if max_count < 0: max_count = len(self.children) - fragment.add_content(self.runtime.service(self, 'mako').render_cms_template( + fragment.add_content(self.runtime.service(self, 'mako').render_template( "library-block-author-preview-header.html", { 'max_count': max_count, 'display_name': self.display_name or self.url_name, @@ -442,7 +442,7 @@ def studio_view(self, _context): Return the studio view. """ fragment = Fragment( - self.runtime.service(self, 'mako').render_cms_template(self.mako_template, self.get_context()) + self.runtime.service(self, 'mako').render_template(self.mako_template, self.get_context()) ) add_webpack_js_to_fragment(fragment, 'LibraryContentBlockEditor') shim_xmodule_js(fragment, self.studio_js_module_name) diff --git a/xmodule/library_root_xblock.py b/xmodule/library_root_xblock.py index cfe2ba6276a..70fb993ba9e 100644 --- a/xmodule/library_root_xblock.py +++ b/xmodule/library_root_xblock.py @@ -104,8 +104,7 @@ def render_children(self, context, fragment, can_reorder=False, can_add=False): }) fragment.add_content( - # For historic reasons, this template is in the LMS folder, and some external code may depend on that. - self.runtime.service(self, 'mako').render_lms_template("studio_render_paged_children_view.html", { + self.runtime.service(self, 'mako').render_template("studio_render_paged_children_view.html", { 'items': contents, 'xblock_context': context, 'can_add': can_add, diff --git a/xmodule/lti_block.py b/xmodule/lti_block.py index 7705a7321bd..4228aec7439 100644 --- a/xmodule/lti_block.py +++ b/xmodule/lti_block.py @@ -381,7 +381,7 @@ def studio_view(self, _context): # Add our specific template information (the raw data body) context.update({'data': self.data}) fragment = Fragment( - self.runtime.service(self, 'mako').render_cms_template(self.mako_template, context) + self.runtime.service(self, 'mako').render_template(self.mako_template, context) ) add_sass_to_fragment(fragment, 'LTIBlockEditor.scss') add_webpack_js_to_fragment(fragment, 'LTIBlockEditor') @@ -498,7 +498,7 @@ def student_view(self, _context): Return the student view. """ fragment = Fragment() - fragment.add_content(self.runtime.service(self, 'mako').render_lms_template('lti.html', self.get_context())) + fragment.add_content(self.runtime.service(self, 'mako').render_template('lti.html', self.get_context())) add_webpack_js_to_fragment(fragment, 'LTIBlockDisplay') shim_xmodule_js(fragment, 'LTI') return fragment @@ -508,7 +508,7 @@ def preview_handler(self, _, __): """ This is called to get context with new oauth params to iframe. """ - template = self.runtime.service(self, 'mako').render_lms_template('lti_form.html', self.get_context()) + template = self.runtime.service(self, 'mako').render_template('lti_form.html', self.get_context()) return Response(template, content_type='text/html') def get_user_id(self): diff --git a/xmodule/poll_block.py b/xmodule/poll_block.py index f09889f506e..c4d9372883e 100644 --- a/xmodule/poll_block.py +++ b/xmodule/poll_block.py @@ -135,7 +135,7 @@ def student_view(self, _context): 'ajax_url': self.ajax_url, 'configuration_json': self.dump_poll(), } - fragment.add_content(self.runtime.service(self, 'mako').render_lms_template('poll.html', params)) + fragment.add_content(self.runtime.service(self, 'mako').render_template('poll.html', params)) add_sass_to_fragment(fragment, 'PollBlockDisplay.scss') add_webpack_js_to_fragment(fragment, 'PollBlockDisplay') shim_xmodule_js(fragment, 'Poll') diff --git a/xmodule/seq_block.py b/xmodule/seq_block.py index 1faa4878086..5561d034da8 100644 --- a/xmodule/seq_block.py +++ b/xmodule/seq_block.py @@ -516,7 +516,7 @@ def _hidden_content_student_view(self, context): if not self._can_user_view_content(course): banner_text = self._hidden_content_banner_text(course) - hidden_content_html = self.runtime.service(self, 'mako').render_lms_template( + hidden_content_html = self.runtime.service(self, 'mako').render_template( 'hidden_content.html', { 'self_paced': course.self_paced, @@ -589,7 +589,7 @@ def _student_or_public_view(self, context, prereq_met, prereq_meta_info, banner_ parent_block_id = self.get_parent().scope_ids.usage_id.block_id params['chapter_completion_aggregator_url'] = '/'.join( [settings.COMPLETION_AGGREGATOR_URL, str(self.scope_ids.usage_id.context_key), parent_block_id]) + '/' - fragment.add_content(self.runtime.service(self, 'mako').render_lms_template("seq_block.html", params)) + fragment.add_content(self.runtime.service(self, 'mako').render_template("seq_block.html", params)) self._capture_full_seq_item_metrics(children) self._capture_current_unit_metrics(children) diff --git a/xmodule/split_test_block.py b/xmodule/split_test_block.py index 88b51db19b3..8984dc62dbb 100644 --- a/xmodule/split_test_block.py +++ b/xmodule/split_test_block.py @@ -282,7 +282,7 @@ def _staff_view(self, context): sorted_inactive_contents = sorted(inactive_contents, key=itemgetter('group_name')) # Use the new template - fragment.add_content(self.runtime.service(self, 'mako').render_lms_template('split_test_staff_view.html', { + fragment.add_content(self.runtime.service(self, 'mako').render_template('split_test_staff_view.html', { 'items': sorted_active_contents + sorted_inactive_contents, })) fragment.add_css('.split-test-child { display: none; }') @@ -309,7 +309,7 @@ def author_view(self, context): fragment, inactive_children, context ) - fragment.add_content(self.runtime.service(self, 'mako').render_lms_template('split_test_author_view.html', { + fragment.add_content(self.runtime.service(self, 'mako').render_template('split_test_author_view.html', { 'split_test': self, 'is_root': is_root, 'is_configured': self.is_configured, @@ -348,7 +348,7 @@ def studio_view(self, context): Return the studio view. """ fragment = Fragment( - self.runtime.service(self, 'mako').render_cms_template(self.mako_template, self.get_context()) + self.runtime.service(self, 'mako').render_template(self.mako_template, self.get_context()) ) add_webpack_js_to_fragment(fragment, 'SplitTestBlockEditor') shim_xmodule_js(fragment, self.studio_js_module_name) @@ -367,7 +367,7 @@ def student_view(self, context): return self._staff_view(context) else: child_fragment = self.child.render(STUDENT_VIEW, context) - fragment = Fragment(self.runtime.service(self, 'mako').render_lms_template('split_test_student_view.html', { + fragment = Fragment(self.runtime.service(self, 'mako').render_template('split_test_student_view.html', { 'child_content': child_fragment.content, 'child_id': self.child.scope_ids.usage_id, })) diff --git a/xmodule/studio_editable.py b/xmodule/studio_editable.py index 4bb7a130b1b..844f0f446c3 100644 --- a/xmodule/studio_editable.py +++ b/xmodule/studio_editable.py @@ -33,9 +33,10 @@ def render_children(self, context, fragment, can_reorder=False, can_add=False): 'content': rendered_child.content }) + # 'lms.' namespace_prefix is required for rendering in studio mako_service = self.runtime.service(self, 'mako') - # For historic reasons, this template is in the LMS folder, and some code like xblock-utils expects that. - fragment.add_content(mako_service.render_lms_template("studio_render_children_view.html", { # pylint: disable=no-member + mako_service.namespace_prefix = 'lms.' + fragment.add_content(mako_service.render_template("studio_render_children_view.html", { # pylint: disable=no-member 'items': contents, 'xblock_context': context, 'can_add': can_add, diff --git a/xmodule/template_block.py b/xmodule/template_block.py index c4813712531..fd537338606 100644 --- a/xmodule/template_block.py +++ b/xmodule/template_block.py @@ -67,7 +67,7 @@ def studio_view(self, _context): Return the studio view. """ fragment = Fragment( - self.runtime.service(self, 'mako').render_cms_template(self.mako_template, self.get_context()) + self.runtime.service(self, 'mako').render_template(self.mako_template, self.get_context()) ) add_sass_to_fragment(fragment, 'CustomTagBlockEditor.scss') add_webpack_js_to_fragment(fragment, 'CustomTagBlockEditor') diff --git a/xmodule/tests/helpers.py b/xmodule/tests/helpers.py index 480771b4177..bfe5297c2a7 100644 --- a/xmodule/tests/helpers.py +++ b/xmodule/tests/helpers.py @@ -56,18 +56,6 @@ def render_template(self, *args, **kwargs): """ return self._render_template(*args, **kwargs) - def render_lms_template(self, *args, **kwargs): - """ - Invokes the configured render_template method. - """ - return self._render_template(*args, **kwargs) - - def render_cms_template(self, *args, **kwargs): - """ - Invokes the configured render_template method. - """ - return self._render_template(*args, **kwargs) - class StubUserService(UserService): """ diff --git a/xmodule/tests/test_conditional.py b/xmodule/tests/test_conditional.py index d1fcde0c756..81eecd09385 100644 --- a/xmodule/tests/test_conditional.py +++ b/xmodule/tests/test_conditional.py @@ -162,7 +162,7 @@ def test_get_html(self): # we reverse it here html = blocks['cond_block'].render(STUDENT_VIEW).content mako_service = blocks['cond_block'].runtime.service(blocks['cond_block'], 'mako') - expected = mako_service.render_lms_template('conditional_ajax.html', { + expected = mako_service.render_template('conditional_ajax.html', { 'ajax_url': blocks['cond_block'].ajax_url, 'element_id': 'i4x-edX-conditional_test-conditional-SampleConditional', 'depends': 'i4x-edX-conditional_test-problem-SampleProblem', @@ -243,7 +243,7 @@ def test_conditional_block(self, _): block = self.get_block_for_location(location) html = block.render(STUDENT_VIEW).content mako_service = block.runtime.service(block, 'mako') - html_expect = mako_service.render_lms_template( + html_expect = mako_service.render_template( 'conditional_ajax.html', { # Test ajax url is just usage-id / handler_name diff --git a/xmodule/tests/test_html_block.py b/xmodule/tests/test_html_block.py index 8cca7acc049..9b769b252ad 100644 --- a/xmodule/tests/test_html_block.py +++ b/xmodule/tests/test_html_block.py @@ -316,7 +316,7 @@ def test_updates_order(self): template_name = f"{info_block.TEMPLATE_DIR}/course_updates.html" info_block.get_html() # Assertion to validate that render function is called with the expected context - info_block.runtime.service(info_block, 'mako').render_lms_template.assert_called_once_with( + info_block.runtime.service(info_block, 'mako').render_template.assert_called_once_with( template_name, expected_context ) diff --git a/xmodule/vertical_block.py b/xmodule/vertical_block.py index d6a19353b2f..11904cfdb3d 100644 --- a/xmodule/vertical_block.py +++ b/xmodule/vertical_block.py @@ -161,8 +161,7 @@ def _student_or_public_view(self, context, view): # lint-amnesty, pylint: disab child_context['username'], str(self.location)), # pylint: disable=no-member }) - mako_service = self.runtime.service(self, 'mako') - fragment.add_content(mako_service.render_lms_template('vert_module.html', fragment_context)) + fragment.add_content(self.runtime.service(self, 'mako').render_template('vert_module.html', fragment_context)) add_webpack_js_to_fragment(fragment, 'VerticalStudentView') fragment.initialize_js('VerticalStudentView') diff --git a/xmodule/video_block/video_block.py b/xmodule/video_block/video_block.py index ef290349b4e..5bf2b3c28cf 100644 --- a/xmodule/video_block/video_block.py +++ b/xmodule/video_block/video_block.py @@ -258,7 +258,7 @@ def studio_view(self, _context): Return the studio view. """ fragment = Fragment( - self.runtime.service(self, 'mako').render_cms_template(self.mako_template, self.get_context()) + self.runtime.service(self, 'mako').render_template(self.mako_template, self.get_context()) ) add_sass_to_fragment(fragment, 'VideoBlockEditor.scss') add_webpack_js_to_fragment(fragment, 'VideoBlockEditor') @@ -498,7 +498,7 @@ def get_html(self, view=STUDENT_VIEW, context=None): # lint-amnesty, pylint: di organization=organization ) - return self.runtime.service(self, 'mako').render_lms_template('video.html', template_context) + return self.runtime.service(self, 'mako').render_template('video.html', template_context) def get_course_video_sharing_override(self): """ diff --git a/xmodule/word_cloud_block.py b/xmodule/word_cloud_block.py index 26a2c38c5cf..6a31da5ef81 100644 --- a/xmodule/word_cloud_block.py +++ b/xmodule/word_cloud_block.py @@ -253,7 +253,7 @@ def student_view(self, context): # lint-amnesty, pylint: disable=unused-argumen Renders the output that a student will see. """ fragment = Fragment() - fragment.add_content(self.runtime.service(self, 'mako').render_lms_template('word_cloud.html', { + fragment.add_content(self.runtime.service(self, 'mako').render_template('word_cloud.html', { 'ajax_url': self.ajax_url, 'display_name': self.display_name, 'instructions': self.instructions, @@ -279,7 +279,7 @@ def studio_view(self, _context): Return the studio view. """ fragment = Fragment( - self.runtime.service(self, 'mako').render_cms_template(self.mako_template, self.get_context()) + self.runtime.service(self, 'mako').render_template(self.mako_template, self.get_context()) ) add_webpack_js_to_fragment(fragment, 'WordCloudBlockEditor') shim_xmodule_js(fragment, self.studio_js_module_name)