Skip to content

Commit

Permalink
chore: Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
farhan committed Oct 2, 2024
1 parent ad23992 commit cabc843
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lms/djangoapps/courseware/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions xmodule/toggles.py
Original file line number Diff line number Diff line change
@@ -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__)
20 changes: 18 additions & 2 deletions xmodule/word_cloud_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 (
Expand All @@ -23,6 +27,7 @@
XModuleMixin,
XModuleToXBlockMixin,
)

log = logging.getLogger(__name__)

# Make '_' a no-op so we can scrape strings. Using lambda instead of
Expand All @@ -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,
Expand All @@ -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."),
Expand All @@ -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(
Expand Down Expand Up @@ -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
)

0 comments on commit cabc843

Please sign in to comment.