From 8b3575669928d6648f021db899bd65bfe84d1256 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Thu, 7 Jun 2018 12:27:18 -0400 Subject: [PATCH] Fix studio xblock failing renders (due to asset hashing loop) --- cms/conftest.py | 12 ++++++++++++ cms/djangoapps/contentstore/views/preview.py | 12 +++++++++++- cms/templates/studio_xblock_wrapper.html | 9 ++------- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/cms/conftest.py b/cms/conftest.py index 99e340933e..d365eb246a 100644 --- a/cms/conftest.py +++ b/cms/conftest.py @@ -47,3 +47,15 @@ def _django_clear_site_cache(): with what has been working for us so far. """ pass + + +@pytest.fixture(autouse=True) +def no_webpack_loader(monkeypatch): + monkeypatch.setattr( + "webpack_loader.templatetags.webpack_loader.render_bundle", + lambda entry, extension=None, config='DEFAULT', attrs='': '' + ) + monkeypatch.setattr( + "webpack_loader.utils.get_as_tags", + lambda entry, extension=None, config='DEFAULT', attrs='': [] + ) diff --git a/cms/djangoapps/contentstore/views/preview.py b/cms/djangoapps/contentstore/views/preview.py index 0b2f0a297e..d43eeba3e5 100644 --- a/cms/djangoapps/contentstore/views/preview.py +++ b/cms/djangoapps/contentstore/views/preview.py @@ -39,7 +39,8 @@ from xmodule.modulestore.django import ModuleI18nService, modulestore from xmodule.partitions.partitions_service import PartitionService from xmodule.services import SettingsService from xmodule.studio_editable import has_author_view -from xmodule.x_module import AUTHOR_VIEW, PREVIEW_VIEWS, STUDENT_VIEW, ModuleSystem +from xmodule.x_module import AUTHOR_VIEW, PREVIEW_VIEWS, STUDENT_VIEW, ModuleSystem, XModule, XModuleDescriptor +import webpack_loader.utils from .helpers import render_from_lms from .session_kv_store import SessionKeyValueStore @@ -298,6 +299,15 @@ def _studio_wrap_xblock(xblock, view, frag, context, display_name_only=False): 'language': getattr(course, 'language', None) } + if isinstance(xblock, (XModule, XModuleDescriptor)): + # Add the webpackified asset tags + class_name = getattr(xblock.__class__, 'unmixed_class', xblock.__class__).__name__ + for tag in webpack_loader.utils.get_as_tags(class_name): + frag.add_resource(tag, mimetype='text/html', placement='head') + + for tag in webpack_loader.utils.get_as_tags("js/factories/xblock_validation"): + frag.add_resource(tag, mimetype='text/html', placement='head') + html = render_to_string('studio_xblock_wrapper.html', template_context) frag = wrap_fragment(frag, html) return frag diff --git a/cms/templates/studio_xblock_wrapper.html b/cms/templates/studio_xblock_wrapper.html index d6e568a849..2e9bc3308a 100644 --- a/cms/templates/studio_xblock_wrapper.html +++ b/cms/templates/studio_xblock_wrapper.html @@ -7,7 +7,6 @@ from lms.lib.utils import is_unit from openedx.core.djangolib.js_utils import ( dump_js_escaped_json, js_escaped_string ) -from xmodule.x_module import XModule, XModuleDescriptor %> <% xblock_url = xblock_studio_url(xblock) @@ -27,7 +26,7 @@ block_is_unit = is_unit(xblock) -<%static:webpack entry="js/factories/xblock_validation"> + % if not is_root: % if is_reorderable: