2525
2626from ..media import api as media_api
2727from ..publishing import api as publishing_api
28- from .models import Component , ComponentType , ComponentVersion , ComponentVersionMedia
28+ from .models import Component , ComponentType , ComponentVersion , ComponentVersionMedia , LearningPackage
2929
3030# The public API that will be re-exported by openedx_content.api
3131# is listed in the __all__ entries below. Internal helper functions that are
@@ -96,7 +96,7 @@ def get_or_create_component_type_by_entity_key(entity_key: str) -> tuple[Compone
9696
9797
9898def create_component (
99- learning_package_id : int ,
99+ learning_package_id : LearningPackage . ID ,
100100 / ,
101101 component_type : ComponentType ,
102102 local_key : str ,
@@ -127,7 +127,7 @@ def create_component(
127127
128128
129129def create_component_version (
130- component_pk : int ,
130+ component_id : Component . ID ,
131131 / ,
132132 version_num : int ,
133133 title : str ,
@@ -139,21 +139,21 @@ def create_component_version(
139139 """
140140 with atomic ():
141141 publishable_entity_version = publishing_api .create_publishable_entity_version (
142- component_pk ,
142+ component_id ,
143143 version_num = version_num ,
144144 title = title ,
145145 created = created ,
146146 created_by = created_by ,
147147 )
148148 component_version = ComponentVersion .objects .create (
149149 publishable_entity_version = publishable_entity_version ,
150- component_id = component_pk ,
150+ component_id = component_id ,
151151 )
152152 return component_version
153153
154154
155155def create_next_component_version (
156- component_pk : int ,
156+ component_id : Component . ID ,
157157 / ,
158158 media_to_replace : dict [str , int | None | bytes ],
159159 created : datetime ,
@@ -167,7 +167,7 @@ def create_next_component_version(
167167 Create a new ComponentVersion based on the most recent version.
168168
169169 Args:
170- component_pk (int): The primary key of the Component to version.
170+ component_id (int): The primary key of the Component to version.
171171 media_to_replace (dict): Mapping of file keys to Media IDs,
172172 None (for deletion), or bytes (for new file media).
173173 created (datetime): The creation timestamp for the new version.
@@ -218,7 +218,7 @@ def create_next_component_version(
218218 # should pick up from the last edited version. Likewise, a Draft might get
219219 # reverted to an earlier version, but we want the latest version_num when
220220 # creating the next version.
221- component = Component .objects .get (pk = component_pk )
221+ component = Component .objects .get (pk = component_id )
222222 last_version = component .versioning .latest
223223 if last_version is None :
224224 next_version_num = 1
@@ -233,15 +233,15 @@ def create_next_component_version(
233233
234234 with atomic ():
235235 publishable_entity_version = publishing_api .create_publishable_entity_version (
236- component_pk ,
236+ component_id ,
237237 version_num = next_version_num ,
238238 title = title ,
239239 created = created ,
240240 created_by = created_by ,
241241 )
242242 component_version = ComponentVersion .objects .create (
243243 publishable_entity_version = publishable_entity_version ,
244- component_id = component_pk ,
244+ component_id = component_id ,
245245 )
246246 # First copy the new stuff over...
247247 for key , media_pk_or_bytes in media_to_replace .items ():
@@ -290,7 +290,7 @@ def create_next_component_version(
290290
291291
292292def create_component_and_version ( # pylint: disable=too-many-positional-arguments
293- learning_package_id : int ,
293+ learning_package_id : LearningPackage . ID ,
294294 / ,
295295 component_type : ComponentType ,
296296 local_key : str ,
@@ -313,7 +313,7 @@ def create_component_and_version( # pylint: disable=too-many-positional-argumen
313313 can_stand_alone = can_stand_alone ,
314314 )
315315 component_version = create_component_version (
316- component .pk ,
316+ component .id ,
317317 version_num = 1 ,
318318 title = title ,
319319 created = created ,
@@ -322,17 +322,17 @@ def create_component_and_version( # pylint: disable=too-many-positional-argumen
322322 return (component , component_version )
323323
324324
325- def get_component (component_pk : int , / ) -> Component :
325+ def get_component (component_id : Component . ID , / ) -> Component :
326326 """
327327 Get Component by its primary key.
328328
329329 This is the same as the PublishableEntity's ID primary key.
330330 """
331- return Component .with_publishing_relations .get (pk = component_pk )
331+ return Component .with_publishing_relations .get (pk = component_id )
332332
333333
334334def get_component_by_key (
335- learning_package_id : int ,
335+ learning_package_id : LearningPackage . ID ,
336336 / ,
337337 namespace : str ,
338338 type_name : str ,
@@ -367,7 +367,7 @@ def get_component_version_by_uuid(uuid: UUID) -> ComponentVersion:
367367
368368
369369def component_exists_by_key (
370- learning_package_id : int ,
370+ learning_package_id : LearningPackage . ID ,
371371 / ,
372372 namespace : str ,
373373 type_name : str ,
@@ -392,7 +392,7 @@ def component_exists_by_key(
392392
393393
394394def get_components ( # pylint: disable=too-many-positional-arguments
395- learning_package_id : int ,
395+ learning_package_id : LearningPackage . ID ,
396396 / ,
397397 draft : bool | None = None ,
398398 published : bool | None = None ,
@@ -435,7 +435,7 @@ def get_components( # pylint: disable=too-many-positional-arguments
435435
436436
437437def get_collection_components (
438- learning_package_id : int ,
438+ learning_package_id : LearningPackage . ID ,
439439 collection_key : str ,
440440) -> QuerySet [Component ]:
441441 """
0 commit comments