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
8 changes: 4 additions & 4 deletions cms/djangoapps/modulestore_migrator/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def _import_assets(migration: models.ModulestoreMigration) -> dict[str, int]:
filename = os.path.basename(old_path)
media_type_str = mimetypes.guess_type(filename)[0] or "application/octet-stream"
media_type = content_api.get_or_create_media_type(media_type_str)
content_by_filename[filename] = content_api.get_or_create_file_content(
content_by_filename[filename] = content_api.get_or_create_file_media(
migration.target_id,
media_type.id,
data=file_data,
Expand Down Expand Up @@ -969,13 +969,13 @@ def _migrate_component(
# If component existed and was deleted or we have to replace the current version
# Create the new component version for it
component_version = libraries_api.set_library_block_olx(target_key, new_olx_str=olx)
for filename, content_pk in context.content_by_filename.items():
for filename, media_pk in context.content_by_filename.items():
filename_no_ext, _ = os.path.splitext(filename)
if filename_no_ext not in olx:
continue
new_path = f"static/{filename}"
content_api.create_component_version_content(
component_version.pk, content_pk, key=new_path
content_api.create_component_version_media(
component_version.pk, media_pk, key=new_path
)

# Publish the component
Expand Down
30 changes: 15 additions & 15 deletions cms/djangoapps/modulestore_migrator/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,13 +405,13 @@ def test_migrate_component_with_static_content(self):
olx = '<problem display_name="Test Problem"><p>See image: test_image.png</p></problem>'

media_type = content_api.get_or_create_media_type("image/png")
test_content = content_api.get_or_create_file_content(
test_media = content_api.get_or_create_file_media(
self.learning_package.id,
media_type.id,
data=b"fake_image_data",
created=timezone.now(),
)
content_by_filename = {"test_image.png": test_content.id}
content_by_filename = {"test_image.png": test_media.id}
context = self._make_migration_context(content_by_filename=content_by_filename)
result, reason = _migrate_component(
context=context,
Expand All @@ -423,11 +423,11 @@ def test_migrate_component_with_static_content(self):
self.assertIsNotNone(result)
self.assertIsNone(reason)

component_content = result.componentversion.componentversioncontent_set.filter(
component_media = result.componentversion.componentversionmedia_set.filter(
key="static/test_image.png"
).first()
self.assertIsNotNone(component_content)
self.assertEqual(component_content.content_id, test_content.id)
self.assertIsNotNone(component_media)
self.assertEqual(component_media.media.id, test_media.id)

def test_migrate_skip_repeats(self):
"""
Expand Down Expand Up @@ -638,13 +638,13 @@ def test_migrate_component_content_filename_not_in_olx(self):
olx = '<problem display_name="Test Problem"><p>See image: referenced.png</p></problem>'

media_type = content_api.get_or_create_media_type("image/png")
referenced_content = content_api.get_or_create_file_content(
referenced_content = content_api.get_or_create_file_media(
self.learning_package.id,
media_type.id,
data=b"referenced_image_data",
created=timezone.now(),
)
unreferenced_content = content_api.get_or_create_file_content(
unreferenced_content = content_api.get_or_create_file_media(
self.learning_package.id,
media_type.id,
data=b"unreferenced_image_data",
Expand All @@ -670,12 +670,12 @@ def test_migrate_component_content_filename_not_in_olx(self):
self.assertIsNone(reason)

referenced_content_exists = (
result.componentversion.componentversioncontent_set.filter(
result.componentversion.componentversionmedia_set.filter(
key="static/referenced.png"
).exists()
)
unreferenced_content_exists = (
result.componentversion.componentversioncontent_set.filter(
result.componentversion.componentversionmedia_set.filter(
key="static/unreferenced.png"
).exists()
)
Expand Down Expand Up @@ -722,7 +722,7 @@ def test_migrate_container_creates_new_container(self):
)
child_version_1 = content_api.create_next_component_version(
child_component_1.pk,
content_to_replace={},
media_to_replace={},
created=timezone.now(),
created_by=self.user.id,
)
Expand All @@ -738,7 +738,7 @@ def test_migrate_container_creates_new_container(self):
)
child_version_2 = content_api.create_next_component_version(
child_component_2.pk,
content_to_replace={},
media_to_replace={},
created=timezone.now(),
created_by=self.user.id,
)
Expand Down Expand Up @@ -910,7 +910,7 @@ def test_migrate_container_preserves_child_order(self):
)
child_version = content_api.create_next_component_version(
child_component.pk,
content_to_replace={},
media_to_replace={},
created=timezone.now(),
created_by=self.user.id,
)
Expand Down Expand Up @@ -950,7 +950,7 @@ def test_migrate_container_with_mixed_child_types(self):
)
problem_version = content_api.create_next_component_version(
problem_component.pk,
content_to_replace={},
media_to_replace={},
created=timezone.now(),
created_by=self.user.id,
)
Expand All @@ -966,7 +966,7 @@ def test_migrate_container_with_mixed_child_types(self):
)
html_version = content_api.create_next_component_version(
html_component.pk,
content_to_replace={},
media_to_replace={},
created=timezone.now(),
created_by=self.user.id,
)
Expand All @@ -982,7 +982,7 @@ def test_migrate_container_with_mixed_child_types(self):
)
video_version = content_api.create_next_component_version(
video_component.pk,
content_to_replace={},
media_to_replace={},
created=timezone.now(),
created_by=self.user.id,
)
Expand Down
34 changes: 17 additions & 17 deletions openedx/core/djangoapps/content_libraries/api/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def set_library_block_olx(usage_key: LibraryUsageLocatorV2, new_olx_str: str) ->
now = datetime.now(tz=timezone.utc)

with transaction.atomic():
new_content = content_api.get_or_create_text_content(
new_content = content_api.get_or_create_text_media(
component.learning_package_id,
get_or_create_olx_media_type(usage_key.block_type).id,
text=new_olx_str,
Expand All @@ -247,7 +247,7 @@ def set_library_block_olx(usage_key: LibraryUsageLocatorV2, new_olx_str: str) ->
new_component_version = content_api.create_next_component_version(
component.pk,
title=new_title,
content_to_replace={
media_to_replace={
'block.xml': new_content.pk,
},
created=now,
Expand Down Expand Up @@ -481,13 +481,13 @@ def _import_staged_block(
media_type_str = "application/octet-stream"

media_type = content_api.get_or_create_media_type(media_type_str)
content = content_api.get_or_create_file_content(
content = content_api.get_or_create_file_media(
learning_package.id,
media_type.id,
data=file_data,
created=now,
)
content_api.create_component_version_content(
content_api.create_component_version_media(
component_version.pk,
content.id,
key=filename,
Expand Down Expand Up @@ -833,30 +833,30 @@ def get_library_block_static_asset_files(usage_key: LibraryUsageLocatorV2) -> li
if component_version is None:
return []

# cvc = the ComponentVersionContent through table
cvc_set = (
# cvm = the ComponentVersionMedia through table
cvm_set = (
component_version
.componentversioncontent_set
.filter(content__has_file=True)
.componentversionmedia_set
.filter(media__has_file=True)
.order_by('key')
.select_related('content')
.select_related('media')
)

site_root_url = get_xblock_app_config().get_site_root_url()

return [
LibraryXBlockStaticFile(
path=cvc.key,
size=cvc.content.size,
path=cvm.key,
size=cvm.media.size,
url=site_root_url + reverse(
'content_libraries:library-assets',
kwargs={
'component_version_uuid': component_version.uuid,
'asset_path': cvc.key,
'asset_path': cvm.key,
}
),
)
for cvc in cvc_set
for cvm in cvm_set
]


Expand Down Expand Up @@ -897,7 +897,7 @@ def add_library_block_static_asset_file(
with transaction.atomic():
component_version = content_api.create_next_component_version(
component.pk,
content_to_replace={file_path: file_content},
media_to_replace={file_path: file_content},
created=datetime.now(tz=timezone.utc),
created_by=user.id if user else None,
)
Expand Down Expand Up @@ -945,7 +945,7 @@ def delete_library_block_static_asset_file(usage_key, file_path, user=None):
with transaction.atomic():
component_version = content_api.create_next_component_version(
component.pk,
content_to_replace={file_path: None},
media_to_replace={file_path: None},
created=now,
created_by=user.id if user else None,
)
Expand Down Expand Up @@ -1038,13 +1038,13 @@ def _create_component_for_block(
created_by=user_id,
can_stand_alone=can_stand_alone,
)
content = content_api.get_or_create_text_content(
content = content_api.get_or_create_text_media(
learning_package.id,
get_or_create_olx_media_type(usage_key.block_type).id,
text=xml_text,
created=now,
)
content_api.create_component_version_content(
content_api.create_component_version_media(
component_version.pk,
content.id,
key="block.xml",
Expand Down
8 changes: 4 additions & 4 deletions openedx/core/djangoapps/content_libraries/rest_api/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,8 @@ def get_component_version_asset(request, component_version_uuid, asset_path):
return redirect_response

# If we got here, we know that the asset exists and it's okay to download.
cv_content = component_version.componentversioncontent_set.get(key=asset_path)
content = cv_content.content
cv_media = component_version.componentversionmedia_set.get(key=asset_path)
media = cv_media.media

# Delete the re-direct part of the response headers. We'll copy the rest.
headers = redirect_response.headers
Expand All @@ -433,7 +433,7 @@ def get_component_version_asset(request, component_version_uuid, asset_path):
# We need to set the content size header manually because this is a
# streaming response. It's not included in the redirect headers because it's
# not needed there (the reverse-proxy would have direct access to the file).
headers['Content-Length'] = content.size
headers['Content-Length'] = media.size

if request.method == "HEAD":
return HttpResponse(headers=headers)
Expand All @@ -442,7 +442,7 @@ def get_component_version_asset(request, component_version_uuid, asset_path):
# offsets or anything fancy, because we don't expect to run this view at
# LMS-scale.
return StreamingHttpResponse(
content.read_file().chunks(),
media.read_file().chunks(),
headers=redirect_response.headers,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def test_missing(self):
)
assert response.status_code == 404

# File-like ComponenVersionContent entry that isn't an actually
# File-like ComponentVersionMedia entry that isn't an actually
# downloadable file...
response = self.client.get(
f"/library_assets/component_versions/{self.draft_component_version.uuid}/block.xml"
Expand Down
12 changes: 6 additions & 6 deletions openedx/core/djangoapps/video_config/transcripts_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,15 +1017,15 @@ def get_transcript_from_openedx_content(video_block, language, output_format, tr

# TODO: There should be a openedx_content API call for this:
try:
content = (
media = (
component_version
.componentversioncontent_set
.filter(content__has_file=True)
.select_related('content')
.componentversionmedia_set
.filter(media__has_file=True)
.select_related('media')
.get(key=file_path)
.content
.media
)
data = content.read_file().read()
data = media.read_file().read()
except ObjectDoesNotExist as exc:
raise NotFoundError(
f"No file {file_path} found for {usage_key} "
Expand Down
4 changes: 2 additions & 2 deletions openedx/core/djangoapps/xblock/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,9 @@ def get_block_olx(
raise NoSuchUsage(usage_key)

# TODO: we should probably make a method on ComponentVersion that returns
# a content based on the name. Accessing by componentversioncontent__key is
# a content based on the name. Accessing by componentversionmedia__key is
# awkward.
content = component_version.contents.get(componentversioncontent__key="block.xml")
content = component_version.media.get(componentversionmedia__key="block.xml")

return content.text

Expand Down
Loading
Loading