Merge pull request #25955 from open-craft/symbolist/convert-hidden-module-to-xblock
[BD-04] [SE-3708] Convert HiddenDescriptor to an XBlock.
This commit is contained in:
@@ -17,7 +17,6 @@ XMODULES = [
|
||||
"videodev = xmodule.backcompat_module:TranslateCustomTagDescriptor",
|
||||
"videosequence = xmodule.seq_module:SequenceDescriptor",
|
||||
"custom_tag_template = xmodule.raw_module:RawDescriptor",
|
||||
"hidden = xmodule.hidden_module:HiddenDescriptor",
|
||||
"raw = xmodule.raw_module:RawDescriptor",
|
||||
"lti = xmodule.lti_module:LTIDescriptor",
|
||||
]
|
||||
@@ -27,6 +26,7 @@ XBLOCKS = [
|
||||
"conditional = xmodule.conditional_module:ConditionalBlock",
|
||||
"course_info = xmodule.html_module:CourseInfoBlock",
|
||||
"error = xmodule.error_module:ErrorBlock",
|
||||
"hidden = xmodule.hidden_module:HiddenDescriptor",
|
||||
"html = xmodule.html_module:HtmlBlock",
|
||||
"library = xmodule.library_root_xblock:LibraryRoot",
|
||||
"library_content = xmodule.library_content_module:LibraryContentBlock",
|
||||
|
||||
@@ -1,20 +1,61 @@
|
||||
"""
|
||||
The Hidden XBlock.
|
||||
"""
|
||||
|
||||
from web_fragments.fragment import Fragment
|
||||
from xblock.core import XBlock
|
||||
from xmodule.raw_module import RawMixin
|
||||
from xmodule.xml_module import XmlMixin
|
||||
from xmodule.x_module import (
|
||||
XModuleDescriptorToXBlockMixin,
|
||||
XModuleMixin,
|
||||
XModuleToXBlockMixin,
|
||||
)
|
||||
|
||||
|
||||
from xmodule.raw_module import RawDescriptor
|
||||
from xmodule.x_module import XModule
|
||||
|
||||
|
||||
class HiddenModule(XModule):
|
||||
@XBlock.needs("i18n")
|
||||
class HiddenDescriptor(
|
||||
RawMixin,
|
||||
XmlMixin,
|
||||
XModuleDescriptorToXBlockMixin,
|
||||
XModuleToXBlockMixin,
|
||||
XModuleMixin,
|
||||
):
|
||||
"""
|
||||
XBlock class loaded by the runtime when another XBlock type has been disabled
|
||||
or an unknown XBlock type is included in a course import.
|
||||
|
||||
The class name includes 'Descriptor' because this used to be an XModule and the class path is specified in the
|
||||
modulestore config in a number of places.
|
||||
"""
|
||||
HIDDEN = True
|
||||
has_author_view = True
|
||||
|
||||
def get_html(self):
|
||||
if self.system.user_is_staff:
|
||||
return u"ERROR: This module is unknown--students will not see it at all"
|
||||
else:
|
||||
return u""
|
||||
|
||||
|
||||
class HiddenDescriptor(RawDescriptor):
|
||||
module_class = HiddenModule
|
||||
resources_dir = None
|
||||
|
||||
def author_view(self, _context):
|
||||
"""
|
||||
Return the author view.
|
||||
"""
|
||||
fragment = Fragment()
|
||||
_ = self.runtime.service(self, "i18n").ugettext
|
||||
content = _(
|
||||
'ERROR: "{block_type}" is an unknown component type. This component will be hidden in LMS.'
|
||||
).format(block_type=self.scope_ids.block_type)
|
||||
fragment.add_content(content)
|
||||
return fragment
|
||||
|
||||
def studio_view(self, _context):
|
||||
"""
|
||||
Return the studio view.
|
||||
"""
|
||||
# User should not be able to edit unknown types.
|
||||
fragment = Fragment()
|
||||
return fragment
|
||||
|
||||
def student_view(self, _context):
|
||||
"""
|
||||
Return the student view.
|
||||
"""
|
||||
fragment = Fragment()
|
||||
return fragment
|
||||
|
||||
@@ -33,7 +33,10 @@ from common.djangoapps.edxmako.shortcuts import render_to_string
|
||||
from xmodule.seq_module import SequenceModule
|
||||
from xmodule.util.xmodule_django import add_webpack_to_fragment
|
||||
from xmodule.vertical_block import VerticalBlock
|
||||
from xmodule.x_module import PREVIEW_VIEWS, STUDIO_VIEW, XModule, XModuleDescriptor, shim_xmodule_js
|
||||
from xmodule.x_module import (
|
||||
PREVIEW_VIEWS, STUDENT_VIEW, STUDIO_VIEW,
|
||||
XModule, XModuleDescriptor, shim_xmodule_js,
|
||||
)
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -110,6 +113,9 @@ def wrap_xblock(
|
||||
)
|
||||
]
|
||||
|
||||
if view == STUDENT_VIEW and getattr(block, 'HIDDEN', False):
|
||||
css_classes.append('is-hidden')
|
||||
|
||||
if isinstance(block, (XModule, XModuleDescriptor)) or getattr(block, 'uses_xmodule_styles_setup', False):
|
||||
if view in PREVIEW_VIEWS:
|
||||
# The block is acting as an XModule
|
||||
@@ -118,9 +124,6 @@ def wrap_xblock(
|
||||
# The block is acting as an XModuleDescriptor
|
||||
css_classes.append('xmodule_edit')
|
||||
|
||||
if getattr(block, 'HIDDEN', False):
|
||||
css_classes.append('is-hidden')
|
||||
|
||||
css_classes.append('xmodule_' + markupsafe.escape(class_name))
|
||||
|
||||
if isinstance(block, (XModule, XModuleDescriptor)):
|
||||
|
||||
Reference in New Issue
Block a user