2222 Collection ,
2323 ComponentType ,
2424 ComponentVersion ,
25- ComponentVersionContent ,
26- Content ,
25+ ComponentVersionMedia ,
2726 LearningPackage ,
27+ Media ,
2828 PublishableEntity ,
2929 PublishableEntityVersion ,
3030)
3131
3232from ..collections import api as collections_api
3333from ..components import api as components_api
34- from ..contents import api as contents_api
34+ from ..media import api as media_api
3535from ..publishing import api as publishing_api
3636from ..sections import api as sections_api
3737from ..subsections import api as subsections_api
@@ -191,14 +191,14 @@ def get_publishable_entities(self) -> QuerySet[PublishableEntity]:
191191 # especially with large libraries (up to 100K items),
192192 # which is too large for this type of prefetch.
193193 Prefetch (
194- "draft__version__componentversion__componentversioncontent_set " ,
195- queryset = ComponentVersionContent .objects .select_related ("content " ),
196- to_attr = "prefetched_contents " ,
194+ "draft__version__componentversion__componentversionmedia_set " ,
195+ queryset = ComponentVersionMedia .objects .select_related ("media " ),
196+ to_attr = "prefetched_media " ,
197197 ),
198198 Prefetch (
199- "published__version__componentversion__componentversioncontent_set " ,
200- queryset = ComponentVersionContent .objects .select_related ("content " ),
201- to_attr = "prefetched_contents " ,
199+ "published__version__componentversion__componentversionmedia_set " ,
200+ queryset = ComponentVersionMedia .objects .select_related ("media " ),
201+ to_attr = "prefetched_media " ,
202202 ),
203203 )
204204 .order_by ("key" )
@@ -372,29 +372,29 @@ def create_zip(self, path: str) -> None:
372372 # ------ COMPONENT STATIC CONTENT -------------
373373 component_version : ComponentVersion = version .componentversion
374374
375- # Get content data associated with this version
376- contents : QuerySet [
377- ComponentVersionContent
378- ] = component_version .prefetched_contents # type: ignore[attr-defined]
375+ # Get media data associated with this version
376+ prefetched_media : QuerySet [
377+ ComponentVersionMedia
378+ ] = component_version .prefetched_media # type: ignore[attr-defined]
379379
380- for component_version_content in contents :
381- content : Content = component_version_content . content
380+ for component_version_media in prefetched_media :
381+ media : Media = component_version_media . media
382382
383- # Important: The component_version_content .key contains implicitly
383+ # Important: The component_version_media .key contains implicitly
384384 # the file name and the file extension
385- file_path = version_folder / component_version_content .key
385+ file_path = version_folder / component_version_media .key
386386
387- if content .has_file and content .path :
387+ if media .has_file and media .path :
388388 # If has_file, we pull it from the file system
389- with content .read_file () as f :
389+ with media .read_file () as f :
390390 file_data = f .read ()
391- elif not content .has_file and content .text :
392- # Otherwise, we use the text content as the file data
393- file_data = content .text
391+ elif not media .has_file and media .text :
392+ # Otherwise, we use the text media as the file data
393+ file_data = media .text
394394 else :
395- # If no file and no text, we skip this content
395+ # If no file and no text, we skip this media
396396 continue
397- self .add_file_to_zip (zipf , file_path , file_data , timestamp = content .created )
397+ self .add_file_to_zip (zipf , file_path , file_data , timestamp = media .created )
398398
399399 # ------ COLLECTION SERIALIZATION -------------
400400 collections = self .get_collections ()
@@ -792,13 +792,13 @@ def _save_components(self, learning_package, components, component_static_files)
792792 for valid_published in components .get ("components_published" , []):
793793 entity_key = valid_published .pop ("entity_key" )
794794 version_num = valid_published ["version_num" ] # Should exist, validated earlier
795- content_to_replace = self ._resolve_static_files (version_num , entity_key , component_static_files )
795+ media_to_replace = self ._resolve_static_files (version_num , entity_key , component_static_files )
796796 self .all_published_entities_versions .add (
797797 (entity_key , version_num )
798798 ) # Track published version
799799 components_api .create_next_component_version (
800800 self .components_map_by_key [entity_key ].publishable_entity .id ,
801- content_to_replace = content_to_replace ,
801+ media_to_replace = media_to_replace ,
802802 force_version_num = valid_published .pop ("version_num" , None ),
803803 created_by = self .user_id ,
804804 ** valid_published
@@ -876,14 +876,14 @@ def _save_draft_versions(self, components, containers, component_static_files):
876876 version_num = valid_draft ["version_num" ] # Should exist, validated earlier
877877 if self ._is_version_already_exists (entity_key , version_num ):
878878 continue
879- content_to_replace = self ._resolve_static_files (version_num , entity_key , component_static_files )
879+ media_to_replace = self ._resolve_static_files (version_num , entity_key , component_static_files )
880880 components_api .create_next_component_version (
881881 self .components_map_by_key [entity_key ].publishable_entity .id ,
882- content_to_replace = content_to_replace ,
882+ media_to_replace = media_to_replace ,
883883 force_version_num = valid_draft .pop ("version_num" , None ),
884- # Drafts can diverge from published, so we allow ignoring previous content
884+ # Drafts can diverge from published, so we allow ignoring previous media
885885 # Use case: published v1 had files A, B; draft v2 only has file A
886- ignore_previous_content = True ,
886+ ignore_previous_media = True ,
887887 created_by = self .user_id ,
888888 ** valid_draft
889889 )
@@ -970,7 +970,7 @@ def _resolve_static_files(
970970 entity_key : str ,
971971 static_files_map : dict [str , List [str ]]
972972 ) -> dict [str , bytes | int ]:
973- """Resolve static file paths into their binary content."""
973+ """Resolve static file paths into their binary media content."""
974974 resolved_files : dict [str , bytes | int ] = {}
975975
976976 static_file_key = f"{ entity_key } :v{ num_version } " # e.g., "xblock.v1:html:my_component_123456:v1"
@@ -979,21 +979,21 @@ def _resolve_static_files(
979979 for static_file in static_files :
980980 local_key = static_file .split (f"v{ num_version } /" )[- 1 ]
981981 with self .zipf .open (static_file , "r" ) as f :
982- content_bytes = f .read ()
982+ media_bytes = f .read ()
983983 if local_key == "block.xml" :
984984 # Special handling for block.xml to ensure
985- # storing the value as a content instance
985+ # storing the value as a media instance
986986 if not self .learning_package_id :
987987 raise ValueError ("learning_package_id must be set before resolving static files." )
988- text_content = contents_api . get_or_create_text_content (
988+ text_media = media_api . get_or_create_text_media (
989989 self .learning_package_id ,
990- contents_api .get_or_create_media_type (f"application/vnd.openedx.xblock.v1.{ block_type } +xml" ).id ,
991- text = content_bytes .decode ("utf-8" ),
990+ media_api .get_or_create_media_type (f"application/vnd.openedx.xblock.v1.{ block_type } +xml" ).id ,
991+ text = media_bytes .decode ("utf-8" ),
992992 created = self .utc_now ,
993993 )
994- resolved_files [local_key ] = text_content .id
994+ resolved_files [local_key ] = text_media .id
995995 else :
996- resolved_files [local_key ] = content_bytes
996+ resolved_files [local_key ] = media_bytes
997997 return resolved_files
998998
999999 def _resolve_children (self , entity_data : dict [str , Any ], lookup_map : dict [str , Any ]) -> list [Any ]:
0 commit comments