Skip to content

Commit

Permalink
feat: get copy to take Learning Core static assets and put them into …
Browse files Browse the repository at this point in the history
…staged content
  • Loading branch information
ormsbee committed Sep 28, 2024
1 parent 55e7efc commit fd21124
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
37 changes: 37 additions & 0 deletions openedx/core/djangoapps/xblock/runtime/learning_core_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from xblock.field_data import FieldData

from openedx.core.lib.xblock_serializer.api import serialize_modulestore_block_for_learning_core
from openedx.core.lib.xblock_serializer.data import StaticFile
from ..learning_context.manager import get_learning_context_impl
from .runtime import XBlockRuntime

Expand Down Expand Up @@ -216,6 +217,42 @@ def get_block(self, usage_key, for_parent=None):

return block

def get_block_assets(self, usage_key):
"""
This currently doesn't copy any
"""
component = self._get_component_from_usage_key(usage_key)
component_version = component.versioning.draft

# If there is no Draft version, then this was soft-deleted
if component_version is None:
return []

# cvc = the ComponentVersionContent through table
cvc_set = (
component_version
.componentversioncontent_set
.filter(content__has_file=True)
.order_by('key')
.select_related('content')
)

return [
StaticFile(
name=cvc.key,
url=None,
# url=reverse(
# 'content_libraries:library-assets',
# kwargs={
# 'component_version_uuid': component_version.uuid,
# 'asset_path': cvc.key,
# }
# ),
data=cvc.content.read_file().read()
)
for cvc in cvc_set
]

def save_block(self, block):
"""
Save any pending field data values to Learning Core data models.
Expand Down
23 changes: 19 additions & 4 deletions openedx/core/lib/xblock_serializer/block_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,25 @@ def __init__(self, block):
# Search the OLX for references to files stored in the course's
# "Files & Uploads" (contentstore):
self.olx_str = utils.rewrite_absolute_static_urls(self.olx_str, course_key)
# for asset in utils.collect_assets_from_text(self.olx_str, course_key):
# path = asset['path']
# if path not in [sf.name for sf in self.static_files]:
# self.static_files.append(StaticFile(name=path, url=asset['url'], data=None))

# If a block supports explicit assets, there's no need to scan the
# content looking for static assets that it *might* be using. Learning
# Core backed content supports this, which currently means v2 Content
# Libraries.
runtime_supports_explicit_assets = hasattr(block.runtime, 'get_block_assets')
if runtime_supports_explicit_assets:
self.static_files.extend(
block.runtime.get_block_assets(block.scope_ids.usage_id)
)
print(f"static_files: {self.static_files}")
return

# Otherwise, we have to scan the content to extract associated asset
# files that are stored in the course-global Files and Uploads.
for asset in utils.collect_assets_from_text(self.olx_str, course_key):
path = asset['path']
if path not in [sf.name for sf in self.static_files]:
self.static_files.append(StaticFile(name=path, url=asset['url'], data=None))

if block.scope_ids.usage_id.block_type in ['problem', 'vertical']:
py_lib_zip_file = utils.get_python_lib_zip_if_using(self.olx_str, course_key)
Expand Down

0 comments on commit fd21124

Please sign in to comment.