Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Waffle flags to roll out the extracted XBlocks #35549

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cms/lib/xblock/tagging/tagging.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from xblock.fields import Dict, Scope

from common.djangoapps.edxmako.shortcuts import render_to_string
from xmodule.capa_block import ProblemBlock # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.x_module import AUTHOR_VIEW # lint-amnesty, pylint: disable=wrong-import-order

_ = lambda text: text
Expand Down Expand Up @@ -42,6 +41,7 @@ def student_view_aside(self, block, context): # pylint: disable=unused-argument
Display the tag selector with specific categories and allowed values,
depending on the context.
"""
from xmodule.capa_block import ProblemBlock
if isinstance(block, ProblemBlock):
tags = []
for tag in self.get_available_tags():
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 = getattr(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
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 @@ -807,6 +809,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 @@ -1275,6 +1278,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 @@ -1285,6 +1289,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.13
# via
# -c requirements/edx/../constraints.txt
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 @@ -565,6 +565,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 @@ -760,6 +761,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 @@ -1352,6 +1354,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 @@ -2252,6 +2255,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 @@ -2270,6 +2274,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.13
# via
# -c requirements/edx/../constraints.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 @@ -415,6 +415,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 @@ -560,6 +561,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 @@ -968,6 +970,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 @@ -1568,6 +1571,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 @@ -1579,6 +1583,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.13
# via
# -c requirements/edx/../constraints.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 @@ -444,6 +444,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 @@ -584,6 +585,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 @@ -1019,6 +1021,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 @@ -1667,6 +1670,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 @@ -1678,6 +1682,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.13
# via
# -c requirements/edx/../constraints.txt
Expand Down
14 changes: 12 additions & 2 deletions xmodule/annotatable_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@
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.toggles import USE_EXTRACTED_ANNOTATABLE_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 (
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,9 @@ 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 USE_EXTRACTED_ANNOTATABLE_BLOCK.is_enabled()
else _BuiltInAnnotatableBlock
)
27 changes: 18 additions & 9 deletions xmodule/capa_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@
from xblock.core import XBlock
from xblock.fields import Boolean, Dict, Float, Integer, Scope, String, XMLString, List
from xblock.scorable import ScorableXBlockMixin, Score
from xblocks_contrib.problem import ProblemBlock as _ExtractedProblemBlock

from common.djangoapps.xblock_django.constants import (
ATTR_KEY_DEPRECATED_ANONYMOUS_USER_ID,
ATTR_KEY_USER_IS_STAFF,
ATTR_KEY_USER_ID,
)
from openedx.core.djangolib.markup import HTML, Text
from xmodule.capa import responsetypes
from xmodule.capa.capa_problem import LoncapaProblem, LoncapaSystem
from xmodule.capa.inputtypes import Status
Expand All @@ -36,23 +43,17 @@
from xmodule.exceptions import NotFoundError, ProcessingError
from xmodule.graders import ShowCorrectness
from xmodule.raw_block import RawMixin
from xmodule.util.sandboxing import SandboxService
from xmodule.toggles import USE_EXTRACTED_PROBLEM_BLOCK
from xmodule.util.builtin_assets import add_webpack_js_to_fragment, add_sass_to_fragment
from xmodule.util.sandboxing import SandboxService
from xmodule.x_module import (
ResourceTemplates,
XModuleMixin,
XModuleToXBlockMixin,
shim_xmodule_js
)
from xmodule.xml_block import XmlMixin
from common.djangoapps.xblock_django.constants import (
ATTR_KEY_DEPRECATED_ANONYMOUS_USER_ID,
ATTR_KEY_USER_IS_STAFF,
ATTR_KEY_USER_ID,
)
from openedx.core.djangolib.markup import HTML, Text
from .capa.xqueue_interface import XQueueService

from .fields import Date, ListScoreField, ScoreField, Timedelta
from .progress import Progress

Expand Down Expand Up @@ -134,7 +135,7 @@ def from_json(self, value):
@XBlock.needs('sandbox')
@XBlock.needs('replace_urls')
@XBlock.wants('call_to_action')
class ProblemBlock(
class _BuiltInProblemBlock(
ScorableXBlockMixin,
RawMixin,
XmlMixin,
Expand All @@ -161,6 +162,8 @@ class ProblemBlock(
"""
INDEX_CONTENT_TYPE = 'CAPA'

is_extracted = False

resources_dir = None

has_score = True
Expand Down Expand Up @@ -2509,3 +2512,9 @@ def randomization_bin(seed, problem_id):
r_hash.update(str(problem_id).encode())
# get the first few digits of the hash, convert to an int, then mod.
return int(r_hash.hexdigest()[:7], 16) % NUM_RANDOMIZATION_BINS


ProblemBlock = (
_ExtractedProblemBlock if USE_EXTRACTED_PROBLEM_BLOCK.is_enabled()
else _BuiltInProblemBlock
)
13 changes: 11 additions & 2 deletions xmodule/discussion_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
from xblock.fields import UNIQUE_ID, Scope, String
from xblock.utils.resources import ResourceLoader
from xblock.utils.studio_editable import StudioEditableXBlockMixin
from xblocks_contrib.discussion import DiscussionXBlock as _ExtractedDiscussionXBlock

from lms.djangoapps.discussion.django_comment_client.permissions import has_permission
from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration, Provider
from openedx.core.djangolib.markup import HTML, Text
from openedx.core.lib.xblock_utils import get_css_dependencies, get_js_dependencies
from xmodule.toggles import USE_EXTRACTED_DISCUSSION_BLOCK
from xmodule.xml_block import XmlMixin


log = logging.getLogger(__name__)
loader = ResourceLoader(__name__) # pylint: disable=invalid-name

Expand All @@ -36,10 +37,11 @@ def _(text):
@XBlock.needs('user') # pylint: disable=abstract-method
@XBlock.needs('i18n')
@XBlock.needs('mako')
class DiscussionXBlock(XBlock, StudioEditableXBlockMixin, XmlMixin): # lint-amnesty, pylint: disable=abstract-method
class _BuiltInDiscussionXBlock(XBlock, StudioEditableXBlockMixin, XmlMixin): # lint-amnesty, pylint: disable=abstract-method
"""
Provides a discussion forum that is inline with other content in the courseware.
"""
is_extracted = False
completion_mode = XBlockCompletionMode.EXCLUDED

discussion_id = String(scope=Scope.settings, default=UNIQUE_ID)
Expand Down Expand Up @@ -275,3 +277,10 @@ def _apply_metadata_and_policy(cls, block, node, runtime):
for field_name, value in metadata.items():
if field_name in block.fields:
setattr(block, field_name, value)


DiscussionXBlock = (
_ExtractedDiscussionXBlock if USE_EXTRACTED_DISCUSSION_BLOCK.is_enabled()
else _BuiltInDiscussionXBlock
)

Loading
Loading