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 64cf575
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
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
23 changes: 23 additions & 0 deletions xmodule/toggles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
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__)
# TODO: Add flag docs once above approved
USE_EXTRACTED_ANNOTATABLE_BLOCK = WaffleFlag('xmodule.use_extracted_block.annotatable', __name__)
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__)
15 changes: 14 additions & 1 deletion 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 @@ -41,7 +45,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 +57,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 Down Expand Up @@ -308,3 +314,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 64cf575

Please sign in to comment.