* 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.
46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
"""
|
|
Mixin class that provides authoring capabilities for XBlocks.
|
|
"""
|
|
|
|
|
|
import logging
|
|
|
|
from django.conf import settings
|
|
from web_fragments.fragment import Fragment
|
|
from xblock.core import XBlock, XBlockMixin
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
VISIBILITY_VIEW = 'visibility_view'
|
|
|
|
|
|
@XBlock.needs("i18n")
|
|
@XBlock.needs("mako")
|
|
class AuthoringMixin(XBlockMixin):
|
|
"""
|
|
Mixin class that provides authoring capabilities for XBlocks.
|
|
"""
|
|
def _get_studio_resource_url(self, relative_url):
|
|
"""
|
|
Returns the Studio URL to a static resource.
|
|
"""
|
|
return settings.STATIC_URL + relative_url
|
|
|
|
def visibility_view(self, _context=None):
|
|
"""
|
|
Render the view to manage an xblock's visibility settings in Studio.
|
|
Args:
|
|
_context: Not actively used for this view.
|
|
Returns:
|
|
(Fragment): An HTML fragment for editing the visibility of this XBlock.
|
|
"""
|
|
fragment = Fragment()
|
|
from cms.djangoapps.contentstore.utils import reverse_course_url
|
|
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),
|
|
}))
|
|
fragment.add_javascript_url(self._get_studio_resource_url('/js/xblock/authoring.js'))
|
|
fragment.initialize_js('VisibilityEditorInit')
|
|
return fragment
|