Skip to content

Commit

Permalink
Add Django settings flags to roll out the extracted XBlocks (openedx#…
Browse files Browse the repository at this point in the history
…35549)

chore: Add Django settings flags to roll out the extracted XBlocks
  • Loading branch information
farhan authored and salman2013 committed Dec 2, 2024
1 parent 1227ce4 commit 96d1235
Show file tree
Hide file tree
Showing 16 changed files with 244 additions and 37 deletions.
10 changes: 10 additions & 0 deletions cms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@
# Password Validator Settings
AUTH_PASSWORD_VALIDATORS
)
from lms.envs.common import (
USE_EXTRACTED_WORD_CLOUD_BLOCK,
USE_EXTRACTED_ANNOTATABLE_BLOCK,
USE_EXTRACTED_POLL_QUESTION_BLOCK,
USE_EXTRACTED_LTI_BLOCK,
USE_EXTRACTED_HTML_BLOCK,
USE_EXTRACTED_DISCUSSION_BLOCK,
USE_EXTRACTED_PROBLEM_BLOCK,
USE_EXTRACTED_VIDEO_BLOCK,
)
from path import Path as path
from django.urls import reverse_lazy

Expand Down
6 changes: 6 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 @@ -1562,6 +1564,10 @@ 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)
block_class = XBlock.load_class(usage_key.block_type)
if hasattr(block_class, 'is_extracted'):
is_extracted = block_class.is_extracted
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
88 changes: 88 additions & 0 deletions lms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5558,3 +5558,91 @@ def _should_send_learning_badge_events(settings):


LMS_COMM_DEFAULT_FROM_EMAIL = "[email protected]"


####################### Setting for built-in Blocks Extraction #######################
# The following Django settings flags have been introduced temporarily to facilitate
# the rollout of the extracted built-in Blocks. 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

# .. toggle_name: USE_EXTRACTED_WORD_CLOUD_BLOCK
# .. toggle_default: False
# .. toggle_implementation: DjangoSetting
# .. toggle_description: Enables the use of the extracted Word Cloud XBlock, which has been shifted to the 'openedx/xblocks-contrib' repo.
# .. toggle_use_cases: temporary
# .. toggle_warning: Not production-ready until https://github.com/openedx/edx-platform/issues/34840 is done.
# .. toggle_creation_date: 2024-11-10
# .. toggle_target_removal_date: 2025-06-01
USE_EXTRACTED_WORD_CLOUD_BLOCK = False

# .. toggle_name: USE_EXTRACTED_ANNOTATABLE_BLOCK
# .. toggle_default: False
# .. toggle_implementation: DjangoSetting
# .. toggle_description: Enables the use of the extracted annotatable XBlock, which has been shifted to the 'openedx/xblocks-contrib' repo.
# .. toggle_use_cases: temporary
# .. toggle_warning: Not production-ready until https://github.com/openedx/edx-platform/issues/34841 is done.
# .. toggle_creation_date: 2024-11-10
# .. toggle_target_removal_date: 2025-06-01
USE_EXTRACTED_ANNOTATABLE_BLOCK = False

# .. toggle_name: USE_EXTRACTED_POLL_QUESTION_BLOCK
# .. toggle_default: False
# .. toggle_implementation: DjangoSetting
# .. toggle_description: Enables the use of the extracted poll question XBlock, which has been shifted to the 'openedx/xblocks-contrib' repo.
# .. toggle_use_cases: temporary
# .. toggle_warning: Not production-ready until https://github.com/openedx/edx-platform/issues/34839 is done.
# .. toggle_creation_date: 2024-11-10
# .. toggle_target_removal_date: 2025-06-01
USE_EXTRACTED_POLL_QUESTION_BLOCK = False

# .. toggle_name: USE_EXTRACTED_LTI_BLOCK
# .. toggle_default: False
# .. toggle_implementation: DjangoSetting
# .. toggle_description: Enables the use of the extracted LTI XBlock, which has been shifted to the 'openedx/xblocks-contrib' repo.
# .. toggle_use_cases: temporary
# .. toggle_warning: Not production-ready until relevant subtask https://github.com/openedx/edx-platform/issues/34827 is done.
# .. toggle_creation_date: 2024-11-10
# .. toggle_target_removal_date: 2025-06-01
USE_EXTRACTED_LTI_BLOCK = False

# .. toggle_name: USE_EXTRACTED_HTML_BLOCK
# .. toggle_default: False
# .. toggle_implementation: DjangoSetting
# .. toggle_description: Enables the use of the extracted HTML XBlock, which has been shifted to the 'openedx/xblocks-contrib' repo.
# .. toggle_use_cases: temporary
# .. toggle_warning: Not production-ready until relevant subtask https://github.com/openedx/edx-platform/issues/34827 is done.
# .. toggle_creation_date: 2024-11-10
# .. toggle_target_removal_date: 2025-06-01
USE_EXTRACTED_HTML_BLOCK = False

# .. toggle_name: USE_EXTRACTED_DISCUSSION_BLOCK
# .. toggle_default: False
# .. toggle_implementation: DjangoSetting
# .. toggle_description: Enables the use of the extracted Discussion XBlock, which has been shifted to the 'openedx/xblocks-contrib' repo.
# .. toggle_use_cases: temporary
# .. toggle_warning: Not production-ready until relevant subtask https://github.com/openedx/edx-platform/issues/34827 is done.
# .. toggle_creation_date: 2024-11-10
# .. toggle_target_removal_date: 2025-06-01
USE_EXTRACTED_DISCUSSION_BLOCK = False

# .. toggle_name: USE_EXTRACTED_PROBLEM_BLOCK
# .. toggle_default: False
# .. toggle_implementation: DjangoSetting
# .. toggle_description: Enables the use of the extracted Problem XBlock, which has been shifted to the 'openedx/xblocks-contrib' repo.
# .. toggle_use_cases: temporary
# .. toggle_warning: Not production-ready until relevant subtask https://github.com/openedx/edx-platform/issues/34827 is done.
# .. toggle_creation_date: 2024-11-10
# .. toggle_target_removal_date: 2025-06-01
USE_EXTRACTED_PROBLEM_BLOCK = False

# .. toggle_name: USE_EXTRACTED_VIDEO_BLOCK
# .. toggle_default: False
# .. toggle_implementation: DjangoSetting
# .. toggle_description: Enables the use of the extracted Video XBlock, which has been shifted to the 'openedx/xblocks-contrib' repo.
# .. toggle_use_cases: temporary
# .. toggle_warning: Not production-ready until relevant subtask https://github.com/openedx/edx-platform/issues/34827 is done.
# .. toggle_creation_date: 2024-11-10
# .. toggle_target_removal_date: 2025-06-01
USE_EXTRACTED_VIDEO_BLOCK = False
6 changes: 6 additions & 0 deletions requirements/edx/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ django-statici18n==2.5.0
# lti-consumer-xblock
# xblock-drag-and-drop-v2
# xblock-poll
# xblocks-contrib
django-storages==1.14.3
# via
# -c requirements/edx/../constraints.txt
Expand Down Expand Up @@ -480,6 +481,7 @@ edx-i18n-tools==1.5.0
# -c requirements/edx/../constraints.txt
# -r requirements/edx/bundled.in
# ora2
# xblocks-contrib
edx-milestones==0.6.0
# via -r requirements/edx/kernel.in
edx-name-affirmation==3.0.1
Expand Down Expand Up @@ -809,6 +811,7 @@ openedx-django-pyfs==3.7.0
# via
# lti-consumer-xblock
# xblock
# xblocks-contrib
openedx-django-require==2.1.0
# via -r requirements/edx/kernel.in
openedx-django-wiki==2.1.0
Expand Down Expand Up @@ -1277,6 +1280,7 @@ xblock[django]==5.1.0
# xblock-drag-and-drop-v2
# xblock-google-drive
# xblock-utils
# xblocks-contrib
xblock-drag-and-drop-v2==4.0.3
# via -r requirements/edx/bundled.in
xblock-google-drive==0.7.0
Expand All @@ -1287,6 +1291,8 @@ xblock-utils==4.0.0
# via
# edx-sga
# xblock-poll
xblocks-contrib==0.1.0
# via -r requirements/edx/bundled.in
xmlsec==1.3.14
# via python3-saml
xss-utils==0.6.0
Expand Down
1 change: 1 addition & 0 deletions requirements/edx/bundled.in
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ ora2>=4.5.0 # Open Response Assessment XBlock
xblock-poll # Xblock for polling users
xblock-drag-and-drop-v2 # Drag and Drop XBlock
xblock-google-drive # XBlock for google docs and calendar
xblocks-contrib # Package having multiple core XBlocks, https://github.com/openedx/xblocks-contrib?tab=readme-ov-file#xblocks-being-moved-here
8 changes: 8 additions & 0 deletions requirements/edx/development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ django-statici18n==2.5.0
# lti-consumer-xblock
# xblock-drag-and-drop-v2
# xblock-poll
# xblocks-contrib
django-storages==1.14.3
# via
# -c requirements/edx/../constraints.txt
Expand Down Expand Up @@ -763,6 +764,7 @@ edx-i18n-tools==1.5.0
# -r requirements/edx/doc.txt
# -r requirements/edx/testing.txt
# ora2
# xblocks-contrib
edx-lint==5.4.1
# via -r requirements/edx/testing.txt
edx-milestones==0.6.0
Expand Down Expand Up @@ -1362,6 +1364,7 @@ openedx-django-pyfs==3.7.0
# -r requirements/edx/testing.txt
# lti-consumer-xblock
# xblock
# xblocks-contrib
openedx-django-require==2.1.0
# via
# -r requirements/edx/doc.txt
Expand Down Expand Up @@ -2266,6 +2269,7 @@ xblock[django]==5.1.0
# xblock-drag-and-drop-v2
# xblock-google-drive
# xblock-utils
# xblocks-contrib
xblock-drag-and-drop-v2==4.0.3
# via
# -r requirements/edx/doc.txt
Expand All @@ -2284,6 +2288,10 @@ xblock-utils==4.0.0
# -r requirements/edx/testing.txt
# edx-sga
# xblock-poll
xblocks-contrib==0.1.0
# via
# -r requirements/edx/doc.txt
# -r requirements/edx/testing.txt
xmlsec==1.3.14
# via
# -r requirements/edx/doc.txt
Expand Down
6 changes: 6 additions & 0 deletions requirements/edx/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ django-statici18n==2.5.0
# lti-consumer-xblock
# xblock-drag-and-drop-v2
# xblock-poll
# xblocks-contrib
django-storages==1.14.3
# via
# -c requirements/edx/../constraints.txt
Expand Down Expand Up @@ -564,6 +565,7 @@ edx-i18n-tools==1.5.0
# -c requirements/edx/../constraints.txt
# -r requirements/edx/base.txt
# ora2
# xblocks-contrib
edx-milestones==0.6.0
# via -r requirements/edx/base.txt
edx-name-affirmation==3.0.1
Expand Down Expand Up @@ -979,6 +981,7 @@ openedx-django-pyfs==3.7.0
# -r requirements/edx/base.txt
# lti-consumer-xblock
# xblock
# xblocks-contrib
openedx-django-require==2.1.0
# via -r requirements/edx/base.txt
openedx-django-wiki==2.1.0
Expand Down Expand Up @@ -1585,6 +1588,7 @@ xblock[django]==5.1.0
# xblock-drag-and-drop-v2
# xblock-google-drive
# xblock-utils
# xblocks-contrib
xblock-drag-and-drop-v2==4.0.3
# via -r requirements/edx/base.txt
xblock-google-drive==0.7.0
Expand All @@ -1596,6 +1600,8 @@ xblock-utils==4.0.0
# -r requirements/edx/base.txt
# edx-sga
# xblock-poll
xblocks-contrib==0.1.0
# via -r requirements/edx/base.txt
xmlsec==1.3.14
# via
# -r requirements/edx/base.txt
Expand Down
6 changes: 6 additions & 0 deletions requirements/edx/testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ django-statici18n==2.5.0
# lti-consumer-xblock
# xblock-drag-and-drop-v2
# xblock-poll
# xblocks-contrib
django-storages==1.14.3
# via
# -c requirements/edx/../constraints.txt
Expand Down Expand Up @@ -585,6 +586,7 @@ edx-i18n-tools==1.5.0
# -c requirements/edx/../constraints.txt
# -r requirements/edx/base.txt
# ora2
# xblocks-contrib
edx-lint==5.4.1
# via -r requirements/edx/testing.in
edx-milestones==0.6.0
Expand Down Expand Up @@ -1024,6 +1026,7 @@ openedx-django-pyfs==3.7.0
# -r requirements/edx/base.txt
# lti-consumer-xblock
# xblock
# xblocks-contrib
openedx-django-require==2.1.0
# via -r requirements/edx/base.txt
openedx-django-wiki==2.1.0
Expand Down Expand Up @@ -1672,6 +1675,7 @@ xblock[django]==5.1.0
# xblock-drag-and-drop-v2
# xblock-google-drive
# xblock-utils
# xblocks-contrib
xblock-drag-and-drop-v2==4.0.3
# via -r requirements/edx/base.txt
xblock-google-drive==0.7.0
Expand All @@ -1683,6 +1687,8 @@ xblock-utils==4.0.0
# -r requirements/edx/base.txt
# edx-sga
# xblock-poll
xblocks-contrib==0.1.0
# via -r requirements/edx/base.txt
xmlsec==1.3.14
# via
# -r requirements/edx/base.txt
Expand Down
15 changes: 13 additions & 2 deletions xmodule/annotatable_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@
import logging
import textwrap

from django.conf import settings
from lxml import etree
from web_fragments.fragment import Fragment
from xblock.core import XBlock
from xblock.fields import Scope, String
from xblocks_contrib.annotatable import AnnotatableBlock as _ExtractedAnnotatableBlock

from openedx.core.djangolib.markup import HTML, Text
from xmodule.editing_block import EditingMixin
from xmodule.raw_block import RawMixin
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 (
ResourceTemplates,
shim_xmodule_js,
XModuleMixin,
XModuleToXBlockMixin,
)
from xmodule.xml_block import XmlMixin

log = logging.getLogger(__name__)

Expand All @@ -28,7 +30,7 @@


@XBlock.needs('mako')
class AnnotatableBlock(
class _BuiltInAnnotatableBlock(
RawMixin,
XmlMixin,
EditingMixin,
Expand All @@ -40,6 +42,8 @@ class AnnotatableBlock(
Annotatable XBlock.
"""

is_extracted = False

data = String(
help=_("XML data for the annotation"),
scope=Scope.content,
Expand Down Expand Up @@ -197,3 +201,10 @@ def studio_view(self, _context):
add_webpack_js_to_fragment(fragment, 'AnnotatableBlockEditor')
shim_xmodule_js(fragment, self.studio_js_module_name)
return fragment


AnnotatableBlock = (
_ExtractedAnnotatableBlock if settings.USE_EXTRACTED_ANNOTATABLE_BLOCK
else _BuiltInAnnotatableBlock
)
AnnotatableBlock.__name__ = "AnnotatableBlock"
Loading

0 comments on commit 96d1235

Please sign in to comment.