[BD-13] Deprecate ModuleSystem.render_template (fixed) (#29354)
* refactor: deprecates ModuleSystem.render_template in favor of the added MakoSystem render_template method. Related changes: * Adds the MakoService to the StudioEditModuleRuntime, PreviewModuleSystem, LmsModuleSystem, and XBlockRuntime * MakoService constructor takes a `namespace_prefix` string, so that the CMS PreviewModuleSystem can render to LMS templates, without needing the special render_from_lms helper method. * ModuleSystem.render_template becomes a read-only property, so the constructor calls and test module systems are updated accordingly. * Adds tests for the MakoService and module system shims. (cherry picked from commit457f959356) * refactor: use MakoService.render_template to remove deprecation warnings from block code. (cherry picked from commit8d62d337f5) * refactor: use MakoService.render_template to remove deprecation warnings from test code. (cherry picked from commit26b43465a4) * test: Adds a test to verify the bug introduced by the previous changes The AuthoringMixin is automatically added to all XBlocks (see settings.XBLOCK_MIXINS), and AuthoringMixin.visibility_view expects the "mako" service. This test verifies the bug by testing the PureXBlock, which does not require the "mako" service, and so fails when the visibility_view is rendered. * fix: AuthoringMixin needs mako service which fixes the visibility_view for XBlocks which don't explicitly require the mako service. Also removes the unneeded class property _services_requested from AuthoringMixin and StudioEditableBlock. This property is better provided by the XBlockMixin class.
This commit is contained in:
@@ -19,6 +19,7 @@ from xblock.field_data import SplitFieldData
|
||||
from xblock.fields import Scope
|
||||
from xblock.runtime import KvsFieldData, MemoryIdManager, Runtime
|
||||
|
||||
from common.djangoapps.edxmako.services import MakoService
|
||||
from common.djangoapps.track import contexts as track_contexts
|
||||
from common.djangoapps.track import views as track_views
|
||||
from common.djangoapps.xblock_django.user_service import DjangoXBlockUserService
|
||||
@@ -235,6 +236,8 @@ class XBlockRuntime(RuntimeShim, Runtime):
|
||||
user_is_staff=self.user.is_staff,
|
||||
anonymous_user_id=self.anonymous_student_id,
|
||||
)
|
||||
elif service_name == "mako":
|
||||
return MakoService()
|
||||
elif service_name == "i18n":
|
||||
return ModuleI18nService(block=block)
|
||||
# Check if the XBlockRuntimeSystem wants to handle this:
|
||||
|
||||
@@ -3,12 +3,12 @@ Code to wrap web fragments with a license.
|
||||
"""
|
||||
|
||||
|
||||
def wrap_with_license(block, view, frag, context): # pylint: disable=unused-argument
|
||||
def wrap_with_license(block, view, frag, context, mako_service): # pylint: disable=unused-argument
|
||||
"""
|
||||
In the LMS, display the custom license underneath the XBlock.
|
||||
"""
|
||||
license = getattr(block, "license", None) # pylint: disable=redefined-builtin
|
||||
if license:
|
||||
context = {"license": license}
|
||||
frag.content += block.runtime.render_template('license_wrapper.html', context)
|
||||
frag.content += mako_service.render_template('license_wrapper.html', context)
|
||||
return frag
|
||||
|
||||
@@ -35,6 +35,7 @@ def _(text):
|
||||
|
||||
@XBlock.needs('user') # pylint: disable=abstract-method
|
||||
@XBlock.needs('i18n')
|
||||
@XBlock.needs('mako')
|
||||
class DiscussionXBlock(XBlock, StudioEditableXBlockMixin, XmlParserMixin): # lint-amnesty, pylint: disable=abstract-method
|
||||
"""
|
||||
Provides a discussion forum that is inline with other content in the courseware.
|
||||
@@ -220,7 +221,8 @@ class DiscussionXBlock(XBlock, StudioEditableXBlockMixin, XmlParserMixin): # li
|
||||
'login_msg': login_msg,
|
||||
}
|
||||
|
||||
fragment.add_content(self.runtime.render_template('discussion/_discussion_inline.html', context))
|
||||
fragment.add_content(self.runtime.service(self, 'mako').render_template('discussion/_discussion_inline.html',
|
||||
context))
|
||||
fragment.initialize_js('DiscussionInlineBlock')
|
||||
|
||||
return fragment
|
||||
@@ -230,7 +232,7 @@ class DiscussionXBlock(XBlock, StudioEditableXBlockMixin, XmlParserMixin): # li
|
||||
Renders author view for Studio.
|
||||
"""
|
||||
fragment = Fragment()
|
||||
fragment.add_content(self.runtime.render_template(
|
||||
fragment.add_content(self.runtime.service(self, 'mako').render_template(
|
||||
'discussion/_discussion_inline_studio.html',
|
||||
{'discussion_id': self.discussion_id}
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user