diff --git a/lms/djangoapps/courseware/views/views.py b/lms/djangoapps/courseware/views/views.py index 79a52db8a0b6..b10fc3dd13cb 100644 --- a/lms/djangoapps/courseware/views/views.py +++ b/lms/djangoapps/courseware/views/views.py @@ -33,6 +33,8 @@ from django.views.generic import View from edx_django_utils.monitoring import set_custom_attribute, set_custom_attributes_for_course_key from ipware.ip import get_client_ip +from xblock.core import XBlock + from lms.djangoapps.static_template_view.views import render_500 from markupsafe import escape from opaque_keys import InvalidKeyError @@ -1551,6 +1553,8 @@ def render_xblock(request, usage_key_string, check_if_enrolled=True, disable_sta set_custom_attributes_for_course_key(course_key) set_custom_attribute('usage_key', usage_key_string) set_custom_attribute('block_type', usage_key.block_type) + if (is_extracted := getattr(XBlock.load_class(usage_key.block_type), 'is_extracted') is not None): + set_custom_attribute('block_extracted', is_extracted) requested_view = request.GET.get('view', 'student_view') if requested_view != 'student_view' and requested_view != 'public_view': # lint-amnesty, pylint: disable=consider-using-in diff --git a/xmodule/toggles.py b/xmodule/toggles.py new file mode 100644 index 000000000000..076d1b03d4b9 --- /dev/null +++ b/xmodule/toggles.py @@ -0,0 +1,32 @@ +""" +Add Waffle flags to roll out the extracted XBlocks. +Flags will use to toggle between the old and new block quickly +without putting course content or user state at risk. + +Ticket: https://github.com/openedx/edx-platform/issues/35308 +""" +from edx_toggles.toggles import WaffleFlag + +# .. toggle_name: USE_EXTRACTED_WORD_CLOUD_BLOCK +# .. toggle_description: Enables the use of the extracted Word Cloud XBlock, which has been shifted to the 'openedx/xblocks-contrib' repo. +# .. toggle_warning: Not production-ready until https://github.com/openedx/edx-platform/issues/34840 is done. +# .. toggle_use_cases: temporary +# .. toggle_default: False +USE_EXTRACTED_WORD_CLOUD_BLOCK = WaffleFlag('xmodule.use_extracted_block.word_cloud', __name__) +# .. toggle_name: USE_EXTRACTED_ANNOTATABLE_BLOCK +# .. toggle_description: Enables the use of the extracted Annotatable XBlock, which has been shifted to the 'openedx/xblocks-contrib' repo. +# .. toggle_warning: Not production-ready until https://github.com/openedx/edx-platform/issues/34841 is done. +# .. toggle_use_cases: temporary +# .. toggle_default: False +USE_EXTRACTED_ANNOTATABLE_BLOCK = WaffleFlag('xmodule.use_extracted_block.annotatable', __name__) +# .. toggle_name: USE_EXTRACTED_POLL_BLOCK +# .. toggle_description: Enables the use of the extracted Poll XBlock, which has been shifted to the 'openedx/xblocks-contrib' repo. +# .. toggle_warning: Not production-ready until https://github.com/openedx/edx-platform/issues/34839 is done. +# .. toggle_use_cases: temporary +# .. toggle_default: False +USE_EXTRACTED_POLL_BLOCK = WaffleFlag('xmodule.use_extracted_block.poll', __name__) +USE_EXTRACTED_LTI_BLOCK = WaffleFlag('xmodule.use_extracted_block.lti', __name__) +USE_EXTRACTED_HTML_BLOCK = WaffleFlag('xmodule.use_extracted_block.html', __name__) +USE_EXTRACTED_DISCUSSION_BLOCK = WaffleFlag('xmodule.use_extracted_block.discussion', __name__) +USE_EXTRACTED_PROBLEM_BLOCK = WaffleFlag('xmodule.use_extracted_block.problem', __name__) +USE_EXTRACTED_VIDEO_BLOCK = WaffleFlag('xmodule.use_extracted_block.video', __name__) diff --git a/xmodule/word_cloud_block.py b/xmodule/word_cloud_block.py index 26a2c38c5cfc..d864da0d3961 100644 --- a/xmodule/word_cloud_block.py +++ b/xmodule/word_cloud_block.py @@ -6,6 +6,9 @@ If student have answered - words he entered and cloud. """ +# TODO: Uncomment following once https://github.com/openedx/edx-platform/issues/34840 is done +# from xblocks_contrib import WordCloudBlock as _ExtractedWordCloudBlock + import json import logging @@ -15,6 +18,7 @@ from xblock.fields import Boolean, Dict, Integer, List, Scope, String from xmodule.editing_block import EditingMixin from xmodule.raw_block import EmptyDataRawMixin +from xmodule.toggles import USE_EXTRACTED_WORD_CLOUD_BLOCK from xmodule.util.builtin_assets import add_webpack_js_to_fragment, add_sass_to_fragment from xmodule.xml_block import XmlMixin from xmodule.x_module import ( @@ -23,6 +27,7 @@ XModuleMixin, XModuleToXBlockMixin, ) + log = logging.getLogger(__name__) # Make '_' a no-op so we can scrape strings. Using lambda instead of @@ -41,7 +46,7 @@ def pretty_bool(value): @XBlock.needs('mako') -class WordCloudBlock( # pylint: disable=abstract-method +class _BuiltInWordCloudBlock( # pylint: disable=abstract-method EmptyDataRawMixin, XmlMixin, EditingMixin, @@ -53,6 +58,8 @@ class WordCloudBlock( # pylint: disable=abstract-method Word Cloud XBlock. """ + is_extracted = False + display_name = String( display_name=_("Display Name"), help=_("The display name for this component."), @@ -61,7 +68,9 @@ class WordCloudBlock( # pylint: disable=abstract-method ) instructions = String( display_name=_("Instructions"), - help=_("Add instructions to help learners understand how to use the word cloud. Clear instructions are important, especially for learners who have accessibility requirements."), # nopep8 pylint: disable=C0301 + help=_( + "Add instructions to help learners understand how to use the word cloud. Clear instructions are important, especially for learners who have accessibility requirements."), + # nopep8 pylint: disable=C0301 scope=Scope.settings, ) num_inputs = Integer( @@ -308,3 +317,10 @@ def index_dictionary(self): xblock_body["content_type"] = "Word Cloud" return xblock_body + + +WordCloudBlock = ( + # _ExractedWordCloudBLock if USE_EXTRACTED_WORD_CLOUD_BLOCK.is_enabled() + _BuiltInWordCloudBlock if USE_EXTRACTED_WORD_CLOUD_BLOCK.is_enabled() + else _BuiltInWordCloudBlock +)