Skip to content

Commit 0919e79

Browse files
committed
fix: extracted html xblock
1 parent 4cba98c commit 0919e79

File tree

13 files changed

+124
-53
lines changed

13 files changed

+124
-53
lines changed

cms/djangoapps/contentstore/tests/test_crud.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
"""Tests for CRUD Operations"""
22

3+
from django.conf import settings
34

45
from xmodule import templates
56
from xmodule.capa_block import ProblemBlock
67
from xmodule.course_block import CourseBlock
7-
from xmodule.html_block import HtmlBlock
88
from xmodule.modulestore import ModuleStoreEnum
99
from xmodule.modulestore.exceptions import DuplicateCourseError
1010
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
11-
from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory
11+
from xmodule.modulestore.tests.factories import BlockFactory, CourseFactory
1212
from xmodule.seq_block import SequenceBlock
1313

1414

@@ -40,11 +40,14 @@ def test_get_templates(self):
4040
self.assertRegex(dropdown['data'], r'<problem>\s*<optionresponse>\s*<p>.*dropdown problems.*')
4141

4242
def test_get_some_templates(self):
43+
course = CourseFactory.create()
44+
htmlblock = BlockFactory.create(category="html", parent_location=course.location)
45+
4346
self.assertEqual(len(SequenceBlock.templates()), 0)
44-
self.assertGreater(len(HtmlBlock.templates()), 0)
47+
self.assertGreater(len(htmlblock.templates()), 0)
4548
self.assertIsNone(SequenceBlock.get_template('doesntexist.yaml'))
46-
self.assertIsNone(HtmlBlock.get_template('doesntexist.yaml'))
47-
self.assertIsNotNone(HtmlBlock.get_template('announcement.yaml'))
49+
self.assertIsNone(htmlblock.get_template('doesntexist.yaml'))
50+
self.assertIsNotNone(htmlblock.get_template('announcement.yaml'))
4851

4952
def test_factories(self):
5053
test_course = CourseFactory.create(

cms/djangoapps/contentstore/xblock_storage_handlers/create_xblock.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ def create_xblock(parent_locator, user, category, display_name, boilerplate=None
3030
data = None
3131
template_id = boilerplate
3232
if template_id:
33-
clz = parent.runtime.load_block_type(category)
34-
if clz is not None:
35-
template = clz.get_template(template_id)
33+
base_clz = parent.runtime.load_block_type(category)
34+
dynamic_clz = parent.runtime.mixologist.mix(base_clz)
35+
if dynamic_clz is not None:
36+
template = dynamic_clz.get_template(template_id)
3637
if template is not None:
3738
metadata = template.get('metadata', {})
3839
data = template.get('data')

cms/envs/common.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@
828828

829829
# Import after sys.path fixup
830830
from xmodule.modulestore.inheritance import InheritanceMixin
831-
from xmodule.x_module import XModuleMixin
831+
from xmodule.x_module import XModuleMixin, ResourceTemplates
832832

833833
# These are the Mixins that will be added to every Blocklike upon instantiation.
834834
# DO NOT EXPAND THIS LIST!! We want it eventually to be EMPTY. Why? Because dynamically adding functions/behaviors to
@@ -841,6 +841,7 @@
841841
# (b) refactor their functionality out of the Blocklike objects and into the edx-platform block runtimes.
842842
LmsBlockMixin,
843843
InheritanceMixin,
844+
ResourceTemplates,
844845
XModuleMixin,
845846
EditInfoMixin,
846847
AuthoringMixin,

openedx/envs/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ def _make_locale_paths(settings):
743743
# .. toggle_warning: Not production-ready until relevant subtask https://github.com/openedx/edx-platform/issues/34827 is done.
744744
# .. toggle_creation_date: 2024-11-10
745745
# .. toggle_target_removal_date: 2025-06-01
746-
USE_EXTRACTED_HTML_BLOCK = False
746+
USE_EXTRACTED_HTML_BLOCK = True
747747

748748
# .. toggle_name: USE_EXTRACTED_DISCUSSION_BLOCK
749749
# .. toggle_default: False

requirements/edx/base.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,7 @@ xblock-utils==4.0.0
12871287
# via
12881288
# edx-sga
12891289
# xblock-poll
1290-
xblocks-contrib==0.4.0
1290+
git+https://github.com/openedx/xblocks-contrib.git@htmlblock
12911291
# via -r requirements/edx/bundled.in
12921292
xmlsec==1.3.14
12931293
# via

requirements/edx/development.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2291,7 +2291,7 @@ xblock-utils==4.0.0
22912291
# -r requirements/edx/testing.txt
22922292
# edx-sga
22932293
# xblock-poll
2294-
xblocks-contrib==0.4.0
2294+
git+https://github.com/openedx/xblocks-contrib.git@htmlblock
22952295
# via
22962296
# -r requirements/edx/doc.txt
22972297
# -r requirements/edx/testing.txt

requirements/edx/doc.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1618,7 +1618,7 @@ xblock-utils==4.0.0
16181618
# -r requirements/edx/base.txt
16191619
# edx-sga
16201620
# xblock-poll
1621-
xblocks-contrib==0.4.0
1621+
git+https://github.com/openedx/xblocks-contrib.git@htmlblock
16221622
# via -r requirements/edx/base.txt
16231623
xmlsec==1.3.14
16241624
# via

requirements/edx/testing.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1701,7 +1701,7 @@ xblock-utils==4.0.0
17011701
# -r requirements/edx/base.txt
17021702
# edx-sga
17031703
# xblock-poll
1704-
xblocks-contrib==0.4.0
1704+
git+https://github.com/openedx/xblocks-contrib.git@htmlblock
17051705
# via -r requirements/edx/base.txt
17061706
xmlsec==1.3.14
17071707
# via

xmodule/discussion_block.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration, Provider
2121
from openedx.core.djangolib.markup import HTML, Text
2222
from openedx.core.lib.xblock_utils import get_css_dependencies, get_js_dependencies
23+
from xmodule.x_module import XModuleMixin
2324
from xmodule.xml_block import XmlMixin
2425

2526
log = logging.getLogger(__name__)
@@ -36,7 +37,7 @@ def _(text):
3637
@XBlock.needs('user') # pylint: disable=abstract-method
3738
@XBlock.needs('i18n')
3839
@XBlock.needs('mako')
39-
class _BuiltInDiscussionXBlock(XBlock, StudioEditableXBlockMixin,
40+
class _BuiltInDiscussionXBlock(XModuleMixin, XBlock, StudioEditableXBlockMixin,
4041
XmlMixin): # lint-amnesty, pylint: disable=abstract-method
4142
"""
4243
Provides a discussion forum that is inline with other content in the courseware.

xmodule/html_block.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,17 @@ def safe_parse_date(date):
494494
return datetime.today()
495495

496496

497-
HtmlBlock = (
498-
_ExtractedHtmlBlock if settings.USE_EXTRACTED_HTML_BLOCK
499-
else _BuiltInHtmlBlock
500-
)
497+
HtmlBlock = None
498+
499+
500+
def reset_class():
501+
"""Reset class as per django settings flag"""
502+
global HtmlBlock
503+
HtmlBlock = (
504+
_ExtractedHtmlBlock if settings.USE_EXTRACTED_HTML_BLOCK
505+
else _BuiltInHtmlBlock
506+
)
507+
return HtmlBlock
508+
509+
reset_class()
501510
HtmlBlock.__name__ = "HtmlBlock"

0 commit comments

Comments
 (0)