Skip to content
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 xblocks_contrib/annotatable/annotatable.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from xblock.fields import Scope, String, XMLString
from xblock.utils.resources import ResourceLoader

from xblocks_contrib.common.xml_utils import LegacyXmlMixin
from xblocks_contrib.legacy_utils.xml_utils import LegacyXmlMixin

log = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion xblocks_contrib/discussion/discussion.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from xblock.utils.resources import ResourceLoader
from xblock.utils.studio_editable import StudioEditableXBlockMixin

from xblocks_contrib.common.xml_utils import LegacyXmlMixin
from xblocks_contrib.legacy_utils.xml_utils import LegacyXmlMixin

log = logging.getLogger(__name__)
loader = ResourceLoader(__name__)
Expand Down
69 changes: 2 additions & 67 deletions xblocks_contrib/html/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
from path import Path as path
from web_fragments.fragment import Fragment
from xblock.core import XBlock
from xblock.fields import Boolean, Scope, String, UserScope
from xblock.fields import Boolean, Scope, String
from xblock.utils.resources import ResourceLoader

from xblocks_contrib.common.xml_utils import LegacyXmlMixin, name_to_pathname
from xblocks_contrib.legacy_utils.xml_utils import LegacyXmlMixin, name_to_pathname

log = logging.getLogger(__name__)
resource_loader = ResourceLoader(__name__)
Expand Down Expand Up @@ -185,18 +185,6 @@ class HtmlBlockMixin(LegacyXmlMixin, XBlock):
uses_xmodule_styles_setup = True
template_dir_name = "html"
show_in_read_only_mode = True
icon_class = "other"

@property
def xblock_kvs(self):
"""
Retrieves the internal KeyValueStore for this XModule.

Should only be used by the persistence layer. Use with caution.
"""
# if caller wants kvs, caller's assuming it's up to date; so, decache it
self.save()
return self._field_data._kvs # pylint: disable=protected-access

@XBlock.supports("multi_device")
def student_view(self, _context):
Expand Down Expand Up @@ -335,59 +323,6 @@ def index_dictionary(self):
xblock_body["content_type"] = "Text"
return xblock_body

def bind_for_student(self, user_id, wrappers=None):
"""
Set up this XBlock to act as an XModule instead of an XModuleDescriptor.

Arguments:
user_id: The user_id to set in scope_ids
wrappers: These are a list functions that put a wrapper, such as
LmsFieldData or OverrideFieldData, around the field_data.
Note that the functions will be applied in the order in
which they're listed. So [f1, f2] -> f2(f1(field_data))
"""

# Skip rebinding if we're already bound a user, and it's this user.
if self.scope_ids.user_id is not None and user_id == self.scope_ids.user_id:
if getattr(self.runtime, "position", None):
# update the position of the tab
self.position = self.runtime.position
return

# # If we are switching users mid-request, save the data from the old user.
# self.save()

# Update scope_ids to point to the new user.
self.scope_ids = self.scope_ids._replace(user_id=user_id)

# Clear out any cached instantiated children.
self.clear_child_cache()

# Clear out any cached field data scoped to the old user.
for field in self.fields.values():
if field.scope in (Scope.parent, Scope.children):
continue

if field.scope.user == UserScope.ONE:
field._del_cached_value(self) # pylint: disable=protected-access
# not the most elegant way of doing this, but if we're removing
# a field from the module's field_data_cache, we should also
# remove it from its _dirty_fields
if field in self._dirty_fields:
del self._dirty_fields[field]

if wrappers:
# Put user-specific wrappers around the field-data service for this block.
# Note that these are different from modulestore.xblock_field_data_wrappers, which are not user-specific.
wrapped_field_data = self.runtime.service(self, "field-data-unbound")
for wrapper in wrappers:
wrapped_field_data = wrapper(wrapped_field_data)
self._bound_field_data = wrapped_field_data
if getattr(self.runtime, "uses_deprecated_field_data", False):
# This approach is deprecated but old mongo's CachingDescriptorSystem still requires it.
# For Split mongo's CachingDescriptor system, don't set ._field_data this way.
self._field_data = wrapped_field_data

@staticmethod
def serialize_asset_key_with_slash(asset_key):
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
"""
⚠️⚠️⚠️ LEGACY FILE — DO NOT USE IN NEW XBLOCKS ⚠️⚠️⚠️

This file is part of an older implementation and is considered **legacy**.

🚫 Do NOT import, extend, or rely on this file when developing new XBlocks.
🚫 Do NOT copy patterns or logic from this file into new code.

This file is maintained ONLY for backward compatibility with existing systems.
It is scheduled for removal in a future cleanup.

If you are building something new, please use the latest supported patterns,
utilities, and modules from the current codebase.

If you are unsure what to use instead, please check the updated documentation
or reach out to the maintainers.

XML utility functions and classes for XBlocks.
Note: Most of the functionality is taken from the edx-platform's XmlMixin.
https://github.com/openedx/edx-platform/blob/master/xmodule/xml_block.py
Expand Down
57 changes: 2 additions & 55 deletions xblocks_contrib/lti/lti.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@
from web_fragments.fragment import Fragment
from webob import Response
from xblock.core import List, Scope, String, XBlock
from xblock.fields import Boolean, Float, UserScope
from xblock.fields import Boolean, Float
from xblock.utils.resources import ResourceLoader
from xblock.utils.studio_editable import StudioEditableXBlockMixin

from xblocks_contrib.common.xml_utils import LegacyXmlMixin
from xblocks_contrib.legacy_utils.xml_utils import LegacyXmlMixin

from .lti_2_util import LTI20BlockMixin, LTIError

Expand Down Expand Up @@ -1017,56 +1017,3 @@ def definition_to_xml(self, resource_fs):
if self.data:
return etree.fromstring(self.data)
return etree.Element(self.usage_key.block_type)

def bind_for_student(self, user_id, wrappers=None):
"""
Set up this XBlock to act as an XModule instead of an XModuleDescriptor.

Arguments:
user_id: The user_id to set in scope_ids
wrappers: These are a list functions that put a wrapper, such as
LmsFieldData or OverrideFieldData, around the field_data.
Note that the functions will be applied in the order in
which they're listed. So [f1, f2] -> f2(f1(field_data))
"""

# Skip rebinding if we're already bound a user, and it's this user.
if self.scope_ids.user_id is not None and user_id == self.scope_ids.user_id:
if getattr(self.runtime, "position", None):
# update the position of the tab
self.position = self.runtime.position # pylint: disable=attribute-defined-outside-init
return

# # If we are switching users mid-request, save the data from the old user.
# self.save()

# Update scope_ids to point to the new user.
self.scope_ids = self.scope_ids._replace(user_id=user_id)

# Clear out any cached instantiated children.
self.clear_child_cache()

# Clear out any cached field data scoped to the old user.
for field in self.fields.values():
if field.scope in (Scope.parent, Scope.children):
continue

if field.scope.user == UserScope.ONE:
field._del_cached_value(self) # pylint: disable=protected-access
# not the most elegant way of doing this, but if we're removing
# a field from the module's field_data_cache, we should also
# remove it from its _dirty_fields
if field in self._dirty_fields:
del self._dirty_fields[field]

if wrappers:
# Put user-specific wrappers around the field-data service for this block.
# Note that these are different from modulestore.xblock_field_data_wrappers, which are not user-specific.
wrapped_field_data = self.runtime.service(self, "field-data-unbound")
for wrapper in wrappers:
wrapped_field_data = wrapper(wrapped_field_data)
self._bound_field_data = wrapped_field_data # pylint: disable=attribute-defined-outside-init
if getattr(self.runtime, "uses_deprecated_field_data", False):
# This approach is deprecated but old mongo's CachingDescriptorSystem still requires it.
# For Split mongo's CachingDescriptor system, don't set ._field_data this way.
self._field_data = wrapped_field_data
30 changes: 1 addition & 29 deletions xblocks_contrib/poll/poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from xblock.fields import Boolean, Dict, List, Scope, String
from xblock.utils.resources import ResourceLoader

from xblocks_contrib.common.xml_utils import LegacyXmlMixin
from xblocks_contrib.legacy_utils.xml_utils import LegacyXmlMixin

Text = markupsafe.escape
resource_loader = ResourceLoader(__name__)
Expand Down Expand Up @@ -107,17 +107,6 @@ class PollBlock(LegacyXmlMixin, XBlock):
_tag_name = "poll_question"
_child_tag_name = "answer"

@property
def xblock_kvs(self):
"""
Retrieves the internal KeyValueStore for this XModule.

Should only be used by the persistence layer. Use with caution.
"""
# if caller wants kvs, caller's assuming it's up to date; so, decache it
self.save()
return self._field_data._kvs # pylint: disable=protected-access

def handle_ajax(self, dispatch, data): # legacy support for tests
"""
Legacy method to mimic old ajax handler behavior for backward compatibility.
Expand Down Expand Up @@ -261,23 +250,6 @@ def workbench_scenarios():
),
]

def get_explicitly_set_fields_by_scope(self, scope=Scope.content):
"""
Get a dictionary of the fields for the given scope which are set explicitly on this xblock. (Including
any set to None.)
"""
result = {}
for field in self.fields.values():
if field.scope == scope and field.is_set_on(self):
try:
result[field.name] = field.read_json(self)
except TypeError as exception:
exception_message = "{message}, Block-location:{location}, Field-name:{field_name}".format(
message=str(exception), location=str(self.usage_key), field_name=field.name
)
raise TypeError(exception_message) # pylint: disable=raise-missing-from
return result

@classmethod
def definition_from_xml(cls, xml_object, system):
"""
Expand Down
Loading
Loading