-
Notifications
You must be signed in to change notification settings - Fork 4.3k
[BD-04] Create CustomTagTemplateBlock, convert TranslateCustomTagDescriptor to XBlock and remove RawDescriptor #26973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
556ef4c
fb02353
78cd8be
23d1e5b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,8 +20,10 @@ | |
| ) | ||
| from xmodule.xml_module import XmlMixin | ||
|
|
||
| from openedx.core.djangolib.markup import Text | ||
|
|
||
| class CustomTagBlock( | ||
|
|
||
| class CustomTagTemplateBlock( # pylint: disable=abstract-method | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| 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 @@ def export_to_file(self): | |
| 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)) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,6 @@ | |
|
|
||
| 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) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| metadata_translations['id'] = 'discussion_id' | ||
| metadata_translations['for'] = 'discussion_target' | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved it to
template_module.py.