Merge pull request #26973 from open-craft/symbolist/convert-to-xblock
[BD-04] Create CustomTagTemplateBlock, convert TranslateCustomTagDescriptor to XBlock and remove RawDescriptor
This commit is contained in:
@@ -101,7 +101,7 @@ class MixedWithOptionsTestCase(MixedSplitTestCase):
|
||||
DATABASE = 'test_mongo_%s' % uuid4().hex[:5]
|
||||
COLLECTION = 'modulestore'
|
||||
ASSET_COLLECTION = 'assetstore'
|
||||
DEFAULT_CLASS = 'xmodule.raw_module.RawDescriptor'
|
||||
DEFAULT_CLASS = 'xmodule.hidden_module.HiddenDescriptor'
|
||||
RENDER_TEMPLATE = lambda t_n, d, ctx=None, nsp='main': ''
|
||||
modulestore_options = {
|
||||
'default_class': DEFAULT_CLASS,
|
||||
|
||||
@@ -98,7 +98,7 @@ BLOCK_STRUCTURES_SETTINGS['PRUNING_ACTIVE'] = True
|
||||
update_module_store_settings(
|
||||
MODULESTORE,
|
||||
module_store_options={
|
||||
'default_class': 'xmodule.raw_module.RawDescriptor',
|
||||
'default_class': 'xmodule.hidden_module.HiddenDescriptor',
|
||||
'fs_root': TEST_ROOT / "data",
|
||||
},
|
||||
doc_store_settings={
|
||||
|
||||
@@ -3,26 +3,23 @@
|
||||
from setuptools import find_packages, setup
|
||||
|
||||
XMODULES = [
|
||||
"book = xmodule.backcompat_module:TranslateCustomTagDescriptor",
|
||||
"discuss = xmodule.backcompat_module:TranslateCustomTagDescriptor",
|
||||
"image = xmodule.backcompat_module:TranslateCustomTagDescriptor",
|
||||
"section = xmodule.backcompat_module:SemanticSectionDescriptor",
|
||||
"slides = xmodule.backcompat_module:TranslateCustomTagDescriptor",
|
||||
"videodev = xmodule.backcompat_module:TranslateCustomTagDescriptor",
|
||||
"custom_tag_template = xmodule.raw_module:RawDescriptor",
|
||||
"raw = xmodule.raw_module:RawDescriptor",
|
||||
]
|
||||
XBLOCKS = [
|
||||
"about = xmodule.html_module:AboutBlock",
|
||||
"book = xmodule.template_module:TranslateCustomTagBlock",
|
||||
"annotatable = xmodule.annotatable_module:AnnotatableBlock",
|
||||
"chapter = xmodule.seq_module:SectionBlock",
|
||||
"conditional = xmodule.conditional_module:ConditionalBlock",
|
||||
"course = xmodule.course_module:CourseBlock",
|
||||
"course_info = xmodule.html_module:CourseInfoBlock",
|
||||
"customtag = xmodule.template_module:CustomTagBlock",
|
||||
"custom_tag_template = xmodule.template_module:CustomTagTemplateBlock",
|
||||
"discuss = xmodule.template_module:TranslateCustomTagBlock",
|
||||
"error = xmodule.error_module:ErrorBlock",
|
||||
"hidden = xmodule.hidden_module:HiddenDescriptor",
|
||||
"html = xmodule.html_module:HtmlBlock",
|
||||
"image = xmodule.template_module:TranslateCustomTagBlock",
|
||||
"library = xmodule.library_root_xblock:LibraryRoot",
|
||||
"library_content = xmodule.library_content_module:LibraryContentBlock",
|
||||
"library_sourced = xmodule.library_sourced_block:LibrarySourcedBlock",
|
||||
@@ -33,12 +30,14 @@ XBLOCKS = [
|
||||
"problemset = xmodule.seq_module:SequenceBlock",
|
||||
"randomize = xmodule.randomize_module:RandomizeBlock",
|
||||
"sequential = xmodule.seq_module:SequenceBlock",
|
||||
"slides = xmodule.template_module:TranslateCustomTagBlock",
|
||||
"split_test = xmodule.split_test_module:SplitTestBlock",
|
||||
"static_tab = xmodule.html_module:StaticTabBlock",
|
||||
"unit = xmodule.unit_block:UnitBlock",
|
||||
"vertical = xmodule.vertical_block:VerticalBlock",
|
||||
"video = xmodule.video_module:VideoBlock",
|
||||
"videoalpha = xmodule.video_module:VideoBlock",
|
||||
"videodev = xmodule.template_module:TranslateCustomTagBlock",
|
||||
"videosequence = xmodule.seq_module:SequenceBlock",
|
||||
"word_cloud = xmodule.word_cloud_module:WordCloudBlock",
|
||||
"wrapper = xmodule.wrapper_module:WrapperBlock",
|
||||
|
||||
@@ -87,25 +87,3 @@ class SemanticSectionDescriptor(XModuleDescriptor): # lint-amnesty, pylint: dis
|
||||
else:
|
||||
xml_object.tag = 'sequential'
|
||||
return system.process_xml(etree.tostring(xml_object))
|
||||
|
||||
|
||||
class TranslateCustomTagDescriptor(XModuleDescriptor): # lint-amnesty, pylint: disable=abstract-method, missing-class-docstring
|
||||
resources_dir = None
|
||||
|
||||
@classmethod
|
||||
def from_xml(cls, xml_data, system, id_generator):
|
||||
"""
|
||||
Transforms the xml_data from <$custom_tag attr="" attr=""/> to
|
||||
<customtag attr="" attr="" impl="$custom_tag"/>
|
||||
"""
|
||||
|
||||
xml_object = etree.fromstring(xml_data)
|
||||
system.error_tracker(Text('WARNING: the <{tag}> tag is deprecated. '
|
||||
'Instead, use <customtag impl="{tag}" attr1="..." attr2="..."/>. ')
|
||||
.format(tag=xml_object.tag))
|
||||
|
||||
tag = xml_object.tag
|
||||
xml_object.tag = 'customtag'
|
||||
xml_object.attrib['impl'] = tag
|
||||
|
||||
return system.process_xml(etree.tostring(xml_object))
|
||||
|
||||
@@ -94,7 +94,7 @@ def draft_mongo_store_config(data_dir):
|
||||
"""
|
||||
|
||||
modulestore_options = {
|
||||
'default_class': 'xmodule.raw_module.RawDescriptor',
|
||||
'default_class': 'xmodule.hidden_module.HiddenDescriptor',
|
||||
'fs_root': data_dir,
|
||||
'render_template': 'common.djangoapps.edxmako.shortcuts.render_to_string'
|
||||
}
|
||||
@@ -121,7 +121,7 @@ def split_mongo_store_config(data_dir):
|
||||
Defines split module store.
|
||||
"""
|
||||
modulestore_options = {
|
||||
'default_class': 'xmodule.raw_module.RawDescriptor',
|
||||
'default_class': 'xmodule.hidden_module.HiddenDescriptor',
|
||||
'fs_root': data_dir,
|
||||
'render_template': 'common.djangoapps.edxmako.shortcuts.render_to_string',
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ class CommonMixedModuleStoreSetup(CourseComparisonTest):
|
||||
COLLECTION = 'modulestore'
|
||||
ASSET_COLLECTION = 'assetstore'
|
||||
FS_ROOT = DATA_DIR
|
||||
DEFAULT_CLASS = 'xmodule.raw_module.RawDescriptor'
|
||||
DEFAULT_CLASS = 'xmodule.hidden_module.HiddenDescriptor'
|
||||
RENDER_TEMPLATE = lambda t_n, d, ctx=None, nsp='main': ''
|
||||
|
||||
MONGO_COURSEID = 'MITx/999/2013_Spring'
|
||||
|
||||
@@ -49,7 +49,7 @@ DB = 'test_mongo_%s' % uuid4().hex[:5]
|
||||
COLLECTION = 'modulestore'
|
||||
ASSET_COLLECTION = 'assetstore'
|
||||
FS_ROOT = DATA_DIR # TODO (vshnayder): will need a real fs_root for testing load_item
|
||||
DEFAULT_CLASS = 'xmodule.raw_module.RawDescriptor'
|
||||
DEFAULT_CLASS = 'xmodule.hidden_module.HiddenDescriptor'
|
||||
RENDER_TEMPLATE = lambda t_n, d, ctx=None, nsp='main': ''
|
||||
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ class SplitModuleTest(unittest.TestCase):
|
||||
'collection': 'modulestore',
|
||||
}
|
||||
modulestore_options = {
|
||||
'default_class': 'xmodule.raw_module.RawDescriptor',
|
||||
'default_class': 'xmodule.hidden_module.HiddenDescriptor',
|
||||
'fs_root': tempdir.mkdtemp_clean(),
|
||||
'xblock_mixins': (InheritanceMixin, XModuleMixin, EditInfoMixin)
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ class SplitWMongoCourseBootstrapper(unittest.TestCase):
|
||||
}
|
||||
|
||||
modulestore_options = {
|
||||
'default_class': 'xmodule.raw_module.RawDescriptor',
|
||||
'default_class': 'xmodule.hidden_module.HiddenDescriptor',
|
||||
'fs_root': '',
|
||||
'render_template': mock.Mock(return_value=""),
|
||||
'xblock_mixins': (InheritanceMixin, XModuleMixin)
|
||||
|
||||
@@ -105,7 +105,7 @@ class MixedSplitTestCase(TestCase):
|
||||
"""
|
||||
RENDER_TEMPLATE = lambda t_n, d, ctx=None, nsp='main': '{}: {}, {}'.format(t_n, repr(d), repr(ctx))
|
||||
modulestore_options = {
|
||||
'default_class': 'xmodule.raw_module.RawDescriptor',
|
||||
'default_class': 'xmodule.hidden_module.HiddenDescriptor',
|
||||
'fs_root': DATA_DIR,
|
||||
'render_template': RENDER_TEMPLATE,
|
||||
'xblock_mixins': (EditInfoMixin, InheritanceMixin, LocationMixin, XModuleMixin),
|
||||
|
||||
@@ -227,7 +227,7 @@ class ImportManager:
|
||||
|
||||
def __init__(
|
||||
self, store, user_id, data_dir, source_dirs=None,
|
||||
default_class='xmodule.raw_module.RawDescriptor',
|
||||
default_class='xmodule.hidden_module.HiddenDescriptor',
|
||||
load_error_modules=True, static_content_store=None,
|
||||
target_id=None, verbose=False,
|
||||
do_import_static=True, do_import_python_lib=True,
|
||||
@@ -1182,7 +1182,7 @@ def validate_course_policy(module_store, course_id):
|
||||
|
||||
def perform_xlint( # lint-amnesty, pylint: disable=missing-function-docstring
|
||||
data_dir, source_dirs,
|
||||
default_class='xmodule.raw_module.RawDescriptor',
|
||||
default_class='xmodule.hidden_module.HiddenDescriptor',
|
||||
load_error_modules=True,
|
||||
xblock_mixins=(LocationMixin, XModuleMixin)):
|
||||
err_cnt = 0
|
||||
|
||||
@@ -99,14 +99,6 @@ class RawMixin:
|
||||
return block
|
||||
|
||||
|
||||
class RawDescriptor(RawMixin, XmlDescriptor, XMLEditingDescriptor):
|
||||
"""
|
||||
Module that provides a raw editing view of its data and children. It
|
||||
requires that the definition xml is valid.
|
||||
"""
|
||||
pass # lint-amnesty, pylint: disable=unnecessary-pass
|
||||
|
||||
|
||||
class EmptyDataRawMixin:
|
||||
"""
|
||||
Common code between EmptyDataRawDescriptor and XBlocks converted from XModules.
|
||||
@@ -125,11 +117,3 @@ class EmptyDataRawMixin:
|
||||
if self.data:
|
||||
return etree.fromstring(self.data)
|
||||
return etree.Element(self.category)
|
||||
|
||||
|
||||
class EmptyDataRawDescriptor(EmptyDataRawMixin, XmlDescriptor, XMLEditingDescriptor):
|
||||
"""
|
||||
Version of RawDescriptor for modules which may have no XML data,
|
||||
but use XMLEditingDescriptor for import/export handling.
|
||||
"""
|
||||
pass # lint-amnesty, pylint: disable=unnecessary-pass
|
||||
|
||||
@@ -20,8 +20,10 @@ from xmodule.x_module import (
|
||||
)
|
||||
from xmodule.xml_module import XmlMixin
|
||||
|
||||
from openedx.core.djangolib.markup import Text
|
||||
|
||||
class CustomTagBlock(
|
||||
|
||||
class CustomTagTemplateBlock( # pylint: disable=abstract-method
|
||||
RawMixin,
|
||||
XmlMixin,
|
||||
EditingMixin,
|
||||
@@ -30,7 +32,15 @@ class CustomTagBlock(
|
||||
HTMLSnippet,
|
||||
ResourceTemplates,
|
||||
XModuleMixin,
|
||||
): # pylint: disable=abstract-method
|
||||
):
|
||||
"""
|
||||
A block which provides templates for CustomTagBlock. The template name
|
||||
is set on the `impl` attribute of CustomTagBlock. See below for more details
|
||||
on how to use it.
|
||||
"""
|
||||
|
||||
|
||||
class CustomTagBlock(CustomTagTemplateBlock): # pylint: disable=abstract-method
|
||||
"""
|
||||
This module supports tags of the form
|
||||
<customtag option="val" option2="val2" impl="tagname"/>
|
||||
@@ -124,3 +134,33 @@ class CustomTagBlock(
|
||||
to export them in a file with yet another layer of indirection.
|
||||
"""
|
||||
return False
|
||||
|
||||
|
||||
class TranslateCustomTagBlock( # pylint: disable=abstract-method
|
||||
XModuleDescriptorToXBlockMixin,
|
||||
XModuleToXBlockMixin,
|
||||
XModuleMixin,
|
||||
):
|
||||
"""
|
||||
Converts olx of the form `<$custom_tag attr="" attr=""/>` to CustomTagBlock
|
||||
of the form `<customtag attr="" attr="" impl="$custom_tag"/>`.
|
||||
"""
|
||||
resources_dir = None
|
||||
|
||||
@classmethod
|
||||
def from_xml(cls, xml_data, system, id_generator):
|
||||
"""
|
||||
Transforms the xml_data from <$custom_tag attr="" attr=""/> to
|
||||
<customtag attr="" attr="" impl="$custom_tag"/>
|
||||
"""
|
||||
|
||||
xml_object = etree.fromstring(xml_data)
|
||||
system.error_tracker(Text('WARNING: the <{tag}> tag is deprecated. '
|
||||
'Instead, use <customtag impl="{tag}" attr1="..." attr2="..."/>. ')
|
||||
.format(tag=xml_object.tag))
|
||||
|
||||
tag = xml_object.tag
|
||||
xml_object.tag = 'customtag'
|
||||
xml_object.attrib['impl'] = tag
|
||||
|
||||
return system.process_xml(etree.tostring(xml_object))
|
||||
|
||||
@@ -2500,7 +2500,7 @@ class TestDisabledXBlockTypes(ModuleStoreTestCase):
|
||||
def test_get_item(self, default_ms):
|
||||
with self.store.default_store(default_ms):
|
||||
course = CourseFactory()
|
||||
self._verify_descriptor('video', course, 'RawDescriptorWithMixins')
|
||||
self._verify_descriptor('video', course, 'HiddenDescriptorWithMixins')
|
||||
|
||||
@ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split)
|
||||
def test_dynamic_updates(self, default_ms):
|
||||
@@ -2515,7 +2515,7 @@ class TestDisabledXBlockTypes(ModuleStoreTestCase):
|
||||
|
||||
# Now simulate a new request cache.
|
||||
self.store.request_cache.data.clear()
|
||||
self._verify_descriptor('problem', course, 'RawDescriptorWithMixins', item_usage_id)
|
||||
self._verify_descriptor('problem', course, 'HiddenDescriptorWithMixins', item_usage_id)
|
||||
|
||||
def _verify_descriptor(self, category, course, descriptor, item_id=None):
|
||||
"""
|
||||
|
||||
@@ -19,7 +19,6 @@ from xblockutils.studio_editable import StudioEditableXBlockMixin
|
||||
|
||||
from openedx.core.djangolib.markup import HTML, Text
|
||||
from openedx.core.lib.xblock_builtin import get_css_dependencies, get_js_dependencies
|
||||
from xmodule.raw_module import RawDescriptor
|
||||
from xmodule.xml_module import XmlParserMixin
|
||||
|
||||
|
||||
@@ -74,7 +73,7 @@ class DiscussionXBlock(XBlock, StudioEditableXBlockMixin, XmlParserMixin): # li
|
||||
has_author_view = True # Tells Studio to use author_view
|
||||
|
||||
# support for legacy OLX format - consumed by XmlParserMixin.load_metadata
|
||||
metadata_translations = dict(RawDescriptor.metadata_translations)
|
||||
metadata_translations = dict(XmlParserMixin.metadata_translations)
|
||||
metadata_translations['id'] = 'discussion_id'
|
||||
metadata_translations['for'] = 'discussion_target'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user