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

refactor: inheritable authoring mixin callbacks for editing & duplication #33756

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
536493f
refactor: inheritable studioeditableblock's callbacks for editing & d…
DanielVZ96 Nov 21, 2023
5901e25
refactor: remove hasattr and add editable studio to cms xblock modules
DanielVZ96 Nov 25, 2023
5c2dabb
fix: tests
DanielVZ96 Nov 25, 2023
3e9bb60
fix: library preview
DanielVZ96 Nov 25, 2023
42c2037
style: ran darker
DanielVZ96 Nov 25, 2023
b4a4c96
style: pylint fixes
DanielVZ96 Nov 25, 2023
aaa26bf
style: use *_args and **_kwargs
DanielVZ96 Nov 30, 2023
116b013
refactor: move load_services_for_studio back into
DanielVZ96 Nov 30, 2023
c5cb3f8
refactor: move editor_saved, post_editor_saved, and studio_post_dupli…
DanielVZ96 Nov 30, 2023
6199588
refactor: move duplication logic into authoringmixin
DanielVZ96 Nov 30, 2023
7f6924f
style: pylint and pep8 fixes
DanielVZ96 Nov 30, 2023
adeec3a
refactor: rename source_item to source_block
DanielVZ96 Nov 30, 2023
cd78eb3
refactor: remove redundant hasattrs due to inheritance
DanielVZ96 Dec 1, 2023
893ff58
Merge branch 'master' into dvz/studio-editable-block-callback-refactor
DanielVZ96 Dec 5, 2023
8ad064c
Merge branch 'master' into dvz/studio-editable-block-callback-refactor
DanielVZ96 Dec 5, 2023
e94fa52
Merge branch 'master' into dvz/studio-editable-block-callback-refactor
DanielVZ96 Dec 8, 2023
3cb2769
revert: remove studio duplicate hooks
DanielVZ96 Jul 7, 2024
5312b5e
Merge branch 'master' into dvz/studio-editable-block-callback-refactor
DanielVZ96 Jul 8, 2024
9c85399
style: fix pylint unused imports
DanielVZ96 Jul 8, 2024
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/djangoapps/contentstore/views/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from opaque_keys.edx.keys import CourseKey
from web_fragments.fragment import Fragment

from cms.djangoapps.contentstore.utils import load_services_for_studio
from cms.lib.xblock.authoring_mixin import VISIBILITY_VIEW
from common.djangoapps.edxmako.shortcuts import render_to_string
from common.djangoapps.student.auth import (
Expand Down Expand Up @@ -47,7 +48,6 @@
from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import (
handle_xblock,
create_xblock_info,
load_services_for_studio,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's an indirect import, should be going directly to contentstore.utils

get_block_info,
get_xblock,
delete_orphans,
Expand Down
2 changes: 1 addition & 1 deletion cms/djangoapps/contentstore/views/preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
wrap_xblock_aside
)

from ..utils import get_visibility_partition_info, StudioPermissionsService
from ..utils import StudioPermissionsService, get_visibility_partition_info
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from formatter

from .access import get_user_role
from .session_kv_store import SessionKeyValueStore

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,10 @@ def _update_with_callback(xblock, user, old_metadata=None, old_content=None):
old_metadata = own_metadata(xblock)
if old_content is None:
old_content = xblock.get_explicitly_set_fields_by_scope(Scope.content)
if hasattr(xblock, "editor_saved"):
load_services_for_studio(xblock.runtime, user)
xblock.editor_saved(user, old_metadata, old_content)
load_services_for_studio(xblock.runtime, user)
xblock.editor_saved(user, old_metadata, old_content)
xblock_updated = modulestore().update_item(xblock, user.id)
if hasattr(xblock_updated, "post_editor_saved"):
load_services_for_studio(xblock_updated.runtime, user)
xblock_updated.post_editor_saved(user, old_metadata, old_content)
xblock_updated.post_editor_saved(user, old_metadata, old_content)
return xblock_updated


Expand Down
16 changes: 16 additions & 0 deletions cms/lib/xblock/authoring_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from xblock.core import XBlock, XBlockMixin
from xblock.fields import String, Scope


log = logging.getLogger(__name__)

VISIBILITY_VIEW = 'visibility_view'
Expand All @@ -21,6 +22,7 @@ class AuthoringMixin(XBlockMixin):
"""
Mixin class that provides authoring capabilities for XBlocks.
"""

def _get_studio_resource_url(self, relative_url):
"""
Returns the Studio URL to a static resource.
Expand Down Expand Up @@ -51,3 +53,17 @@ def visibility_view(self, _context=None):
scope=Scope.settings,
enforce_type=True,
)

def editor_saved(self, user, old_metadata, old_content) -> None: # pylint: disable=unused-argument
"""
Called right *before* the block is written to the DB. Can be used, e.g., to modify fields before saving.

By default, is a no-op. Can be overriden in subclasses.
"""

def post_editor_saved(self, user, old_metadata, old_content) -> None: # pylint: disable=unused-argument
"""
Called right *after* the block is written to the DB. Can be used, e.g., to spin up followup tasks.

By default, is a no-op. Can be overriden in subclasses.
"""
Agrendalath marked this conversation as resolved.
Show resolved Hide resolved
43 changes: 2 additions & 41 deletions xmodule/studio_editable.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Mixin to support editing in Studio.
"""
from xblock.core import XBlock, XBlockMixin

from xmodule.x_module import AUTHOR_VIEW, STUDENT_VIEW


Expand All @@ -12,6 +13,7 @@ class StudioEditableBlock(XBlockMixin):

This class is only intended to be used with an XBlock!
"""

has_author_view = True
DanielVZ96 marked this conversation as resolved.
Show resolved Hide resolved

def render_children(self, context, fragment, can_reorder=False, can_add=False):
Expand Down Expand Up @@ -49,47 +51,6 @@ def get_preview_view_name(block):
"""
return AUTHOR_VIEW if has_author_view(block) else STUDENT_VIEW

# Some parts of the code use getattr to dynamically check for the following methods on subclasses.
# We'd like to refactor so that we can actually declare them here as overridable methods.
# For now, we leave them here as documentation.
# See https://github.com/openedx/edx-platform/issues/33715.
#
# def editor_saved(self, old_metadata, old_content) -> None: # pylint: disable=unused-argument
# """
# Called right *before* the block is written to the DB. Can be used, e.g., to modify fields before saving.
#
# By default, is a no-op. Can be overriden in subclasses.
# """
#
# def post_editor_saved(self, old_metadata, old_content) -> None: # pylint: disable=unused-argument
# """
# Called right *after* the block is written to the DB. Can be used, e.g., to spin up followup tasks.
#
# By default, is a no-op. Can be overriden in subclasses.
# """
#
# def studio_post_duplicate(self, store, source_block) -> bool: # pylint: disable=unused-argument
# """
# Called when a the block is duplicated. Can be used, e.g., for special handling of child duplication.
#
# Returns 'True' if children have been handled and thus shouldn't be handled by the standard
# duplication logic.
#
# By default, is a no-op. Can be overriden in subclasses.
# """
# return False
#
# def studio_post_paste(self, store, source_node) -> bool: # pylint: disable=unused-argument
# """
# Called after a block is copy-pasted. Can be used, e.g., for special handling of child duplication.
#
# Returns 'True' if children have been handled and thus shouldn't be handled by the standard
# duplication logic.
#
# By default, is a no-op. Can be overriden in subclasses.
# """
# return False


def has_author_view(block):
"""
Expand Down
Loading