Skip to content
Merged
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 openedx/core/djangoapps/content_libraries/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@
LIBRARY_BLOCK_UPDATED,
LIBRARY_BLOCK_DELETED,
)
from openedx.core.djangoapps.olx_rest_api.api import serialize_modulestore_block_for_blockstore
from openedx.core.djangoapps.xblock.api import (
get_block_display_name,
get_learning_context_impl,
load_block,
XBlockInclude,
)
from openedx.core.lib.xblock_serializer.api import serialize_modulestore_block_for_blockstore
from openedx.core.lib.blockstore_api import (
get_bundle,
get_bundles,
Expand Down
99 changes: 0 additions & 99 deletions openedx/core/djangoapps/content_staging/block_serializer.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def test_copy_html(self):
# For HTML, we really want to be sure that the OLX is serialized in this exact format (using CDATA), so we check
# the actual string directly rather than using assertXmlEqual():
self.assertEqual(olx_response.content.decode(), dedent("""
<html display_name="Text"><![CDATA[
<html url_name="toyhtml" display_name="Text"><![CDATA[
<a href='/static/handouts/sample_handout.txt'>Sample</a>
]]></html>
""").lstrip())
Expand Down
4 changes: 2 additions & 2 deletions openedx/core/djangoapps/content_staging/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
from common.djangoapps.student.auth import has_studio_read_access

from openedx.core.lib.api.view_utils import view_auth_classes
from openedx.core.lib.xblock_serializer.api import serialize_xblock_to_olx
from xmodule import block_metadata_utils
from xmodule.modulestore.django import modulestore
from xmodule.modulestore.exceptions import ItemNotFoundError

from .block_serializer import XBlockSerializer
from .models import StagedContent, UserClipboard
from .serializers import UserClipboardSerializer, PostToClipboardSerializer
from .tasks import delete_expired_clipboards
Expand Down Expand Up @@ -110,7 +110,7 @@ def post(self, request):
block = modulestore().get_item(usage_key)
except ItemNotFoundError as exc:
raise NotFound("The requested usage key does not exist.") from exc
block_data = XBlockSerializer(block)
block_data = serialize_xblock_to_olx(block)

expired_ids = []
with transaction.atomic():
Expand Down
21 changes: 2 additions & 19 deletions openedx/core/djangoapps/olx_rest_api/api.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
"""
Public Python API for the OLX REST API app
"""
from .block_serializer import XBlockSerializer as _XBlockSerializer
# pylint: disable=unused-import
# 'adapters' are _temporarily_ part of the public API to keep the code DRY until
# we can consolidate the two different block_serializer implementations in
# content_staging and olx_rest_api.
from . import adapters


def serialize_modulestore_block_for_blockstore(block):
"""
Given a modulestore XBlock (e.g. loaded using
modulestore.get_item(block_key)
), produce:
(1) A new definition ID for use in Blockstore
(2) an XML string defining the XBlock and referencing the IDs of its
children (but not containing the actual XML of its children)
(3) a list of any static files required by the XBlock and their URL
"""
return _XBlockSerializer(block)
# Currently there is no python API here. See openedx.core.lib.xblock_serializer
# for a python API to serialize XBlocks to OLX.
6 changes: 3 additions & 3 deletions openedx/core/djangoapps/olx_rest_api/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
from openedx.core.djangolib.testing.utils import skip_unless_cms
from common.djangoapps.student.roles import CourseStaffRole
from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory
from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore.tests.factories import ToyCourseFactory # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore import ModuleStoreEnum
from xmodule.modulestore.tests.django_utils import SharedModuleStoreTestCase
from xmodule.modulestore.tests.factories import ToyCourseFactory


@skip_unless_cms
Expand Down
12 changes: 6 additions & 6 deletions openedx/core/djangoapps/olx_rest_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

from common.djangoapps.student.auth import has_studio_read_access
from openedx.core.lib.api.view_utils import view_auth_classes
from xmodule.modulestore.django import modulestore

from . import adapters
from .block_serializer import XBlockSerializer
from openedx.core.lib.xblock_serializer.api import serialize_modulestore_block_for_blockstore


@api_view(['GET'])
Expand Down Expand Up @@ -47,8 +47,8 @@ def serialize_block(block_key):
if block_key in serialized_blocks:
return

block = adapters.get_block(block_key)
serialized_blocks[block_key] = XBlockSerializer(block)
block = modulestore().get_item(block_key)
serialized_blocks[block_key] = serialize_modulestore_block_for_blockstore(block)

if block.has_children:
for child_id in block.children:
Expand Down Expand Up @@ -102,8 +102,8 @@ def get_block_exportfs_file(request, usage_key_str, path):
if not has_studio_read_access(request.user, course_key):
raise PermissionDenied("You must be a member of the course team in Studio to export OLX using this API.")

block = adapters.get_block(usage_key)
serialized = XBlockSerializer(block)
block = modulestore().get_item(usage_key)
serialized = serialize_modulestore_block_for_blockstore(block)
static_file = None
for f in serialized.static_files:
if f.name == path:
Expand Down
Empty file.
27 changes: 27 additions & 0 deletions openedx/core/lib/xblock_serializer/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
Public python API for serializing XBlocks to OLX
"""
# pylint: disable=unused-import
from .block_serializer import StaticFile, XBlockSerializer, XBlockSerializerForBlockstore


def serialize_xblock_to_olx(block):
"""
This class will serialize an XBlock, producing:
(1) an XML string defining the XBlock and all of its children (inline)
(2) a list of any static files required by the XBlock and their URL
"""
return XBlockSerializer(block)


def serialize_modulestore_block_for_blockstore(block):
"""
This class will serialize an XBlock, producing:
(1) A new definition ID for use in Blockstore
(2) an XML string defining the XBlock and referencing the IDs of its
children using <xblock-include /> syntax (which doesn't actually
contain the OLX of its children, just refers to them, so you have to
separately serialize them.)
(3) a list of any static files required by the XBlock and their URL
"""
return XBlockSerializerForBlockstore(block)
Loading