From 1df53ab3673bff2174a790abea4e7f8f2f41188c Mon Sep 17 00:00:00 2001 From: farhan Date: Wed, 13 Nov 2024 15:41:15 +0500 Subject: [PATCH] chore: Adds waffle flag on word cloud xblock --- xmodule/tests/test_word_cloud.py | 13 +++++--- xmodule/toggles.py | 54 ++++++++++++++++++++++++++++++-- xmodule/word_cloud_block.py | 12 ++++++- 3 files changed, 71 insertions(+), 8 deletions(-) diff --git a/xmodule/tests/test_word_cloud.py b/xmodule/tests/test_word_cloud.py index 6c928465262b..361833ff513a 100644 --- a/xmodule/tests/test_word_cloud.py +++ b/xmodule/tests/test_word_cloud.py @@ -10,7 +10,6 @@ from webob.multidict import MultiDict from xblock.field_data import DictFieldData -from xmodule.word_cloud_block import WordCloudBlock from . import get_test_descriptor_system, get_test_system @@ -19,6 +18,10 @@ class WordCloudBlockTest(TestCase): Logic tests for Word Cloud Block. """ + def setUp(self): + from xmodule.word_cloud_block import WordCloudBlock + self.WordCloudBlock = WordCloudBlock + raw_field_data = { 'all_words': {'cat': 10, 'dog': 5, 'mom': 1, 'dad': 2}, 'top_words': {'cat': 10, 'dog': 5, 'dad': 2}, @@ -42,7 +45,7 @@ def test_xml_import_export_cycle(self): olx_element = etree.fromstring(original_xml) runtime.id_generator = Mock() - block = WordCloudBlock.parse_xml(olx_element, runtime, None) + block = self.WordCloudBlock.parse_xml(olx_element, runtime, None) block.location = BlockUsageLocator( CourseLocator('org', 'course', 'run', branch='revision'), 'word_cloud', 'block_id' ) @@ -67,7 +70,7 @@ def test_bad_ajax_request(self): """ module_system = get_test_system() - block = WordCloudBlock(module_system, DictFieldData(self.raw_field_data), Mock()) + block = self.WordCloudBlock(module_system, DictFieldData(self.raw_field_data), Mock()) response = json.loads(block.handle_ajax('bad_dispatch', {})) self.assertDictEqual(response, { @@ -81,7 +84,7 @@ def test_good_ajax_request(self): """ module_system = get_test_system() - block = WordCloudBlock(module_system, DictFieldData(self.raw_field_data), Mock()) + block = self.WordCloudBlock(module_system, DictFieldData(self.raw_field_data), Mock()) post_data = MultiDict(('student_words[]', word) for word in ['cat', 'cat', 'dog', 'sun']) response = json.loads(block.handle_ajax('submit', post_data)) @@ -110,7 +113,7 @@ def test_indexibility(self): """ module_system = get_test_system() - block = WordCloudBlock(module_system, DictFieldData(self.raw_field_data), Mock()) + block = self.WordCloudBlock(module_system, DictFieldData(self.raw_field_data), Mock()) assert block.index_dictionary() ==\ {'content_type': 'Word Cloud', 'content': {'display_name': 'Word Cloud Block', diff --git a/xmodule/toggles.py b/xmodule/toggles.py index 7fc1fc774bfe..110479ab5b24 100644 --- a/xmodule/toggles.py +++ b/xmodule/toggles.py @@ -12,12 +12,62 @@ # .. toggle_warning: Not production-ready until https://github.com/openedx/edx-platform/issues/34840 is done. # .. toggle_use_cases: temporary # .. toggle_default: False +# .. toggle_implementation: +# .. toggle_creation_date: 10th Nov, 2024 USE_EXTRACTED_WORD_CLOUD_BLOCK = WaffleFlag('xmodule.use_extracted_block.word_cloud', __name__) -# TODO: Add flag docs once above approved +# .. 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 +# .. toggle_implementation: +# .. toggle_creation_date: 10th Nov, 2024 USE_EXTRACTED_ANNOTATABLE_BLOCK = WaffleFlag('xmodule.use_extracted_block.annotatable', __name__) -USE_EXTRACTED_POLL_BLOCK = WaffleFlag('xmodule.use_extracted_block.poll', __name__) +# .. toggle_name: USE_EXTRACTED_POLL_QUESTION_BLOCK +# .. toggle_description: Enables the use of the extracted poll question 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 +# .. toggle_implementation: +# .. toggle_creation_date: 10th Nov, 2024 +USE_EXTRACTED_POLL_QUESTION_BLOCK = WaffleFlag('xmodule.use_extracted_block.poll_question', __name__) +# .. toggle_name: USE_EXTRACTED_LTI_BLOCK +# .. toggle_description: Enables the use of the extracted lti XBlock, which has been shifted to the 'openedx/xblocks-contrib' repo. +# .. toggle_warning: Not production-ready until relevant subtask https://github.com/openedx/edx-platform/issues/34827 is done. +# .. toggle_use_cases: temporary +# .. toggle_default: False +# .. toggle_implementation: +# .. toggle_creation_date: 10th Nov, 2024 USE_EXTRACTED_LTI_BLOCK = WaffleFlag('xmodule.use_extracted_block.lti', __name__) +# .. toggle_name: USE_EXTRACTED_HTML_BLOCK +# .. toggle_description: Enables the use of the extracted html XBlock, which has been shifted to the 'openedx/xblocks-contrib' repo. +# .. toggle_warning: Not production-ready until relevant subtask https://github.com/openedx/edx-platform/issues/34827 is done. +# .. toggle_use_cases: temporary +# .. toggle_default: False +# .. toggle_implementation: +# .. toggle_creation_date: 10th Nov, 2024 USE_EXTRACTED_HTML_BLOCK = WaffleFlag('xmodule.use_extracted_block.html', __name__) +# .. toggle_name: USE_EXTRACTED_DISCUSSION_BLOCK +# .. toggle_description: Enables the use of the extracted discussion XBlock, which has been shifted to the 'openedx/xblocks-contrib' repo. +# .. toggle_warning: Not production-ready until relevant subtask https://github.com/openedx/edx-platform/issues/34827 is done. +# .. toggle_use_cases: temporary +# .. toggle_default: False +# .. toggle_implementation: +# .. toggle_creation_date: 10th Nov, 2024 USE_EXTRACTED_DISCUSSION_BLOCK = WaffleFlag('xmodule.use_extracted_block.discussion', __name__) +# .. toggle_name: USE_EXTRACTED_PROBLEM_BLOCK +# .. toggle_description: Enables the use of the extracted problem XBlock, which has been shifted to the 'openedx/xblocks-contrib' repo. +# .. toggle_warning: Not production-ready until relevant subtask https://github.com/openedx/edx-platform/issues/34827 is done. +# .. toggle_use_cases: temporary +# .. toggle_default: False +# .. toggle_implementation: +# .. toggle_creation_date: 10th Nov, 2024 USE_EXTRACTED_PROBLEM_BLOCK = WaffleFlag('xmodule.use_extracted_block.problem', __name__) +# .. toggle_name: USE_EXTRACTED_VIDEO_BLOCK +# .. toggle_description: Enables the use of the extracted video XBlock, which has been shifted to the 'openedx/xblocks-contrib' repo. +# .. toggle_warning: Not production-ready until relevant subtask https://github.com/openedx/edx-platform/issues/34827 is done. +# .. toggle_use_cases: temporary +# .. toggle_default: False +# .. toggle_implementation: +# .. toggle_creation_date: 10th Nov, 2024 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 d678f2a9a9f5..18249d453f43 100644 --- a/xmodule/word_cloud_block.py +++ b/xmodule/word_cloud_block.py @@ -15,6 +15,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_css_to_fragment from xmodule.xml_block import XmlMixin from xmodule.x_module import ( @@ -23,6 +24,7 @@ XModuleMixin, XModuleToXBlockMixin, ) +from xblocks_contrib.word_cloud import WordCloudBlock as _ExtractedWordCloudBlock log = logging.getLogger(__name__) # Make '_' a no-op so we can scrape strings. Using lambda instead of @@ -41,7 +43,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 +55,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."), @@ -308,3 +312,9 @@ def index_dictionary(self): xblock_body["content_type"] = "Word Cloud" return xblock_body + + +WordCloudBlock = ( + _ExtractedWordCloudBlock if USE_EXTRACTED_WORD_CLOUD_BLOCK.is_enabled() + else _BuiltInWordCloudBlock +)