@@ -62,8 +62,7 @@ def create_subsection_version(
6262 version_num : int ,
6363 * ,
6464 title : str ,
65- publishable_entities_pks : list [int ],
66- entity_version_pks : list [int | None ],
65+ entity_rows : list [publishing_api .ContainerEntityRow ],
6766 created : datetime ,
6867 created_by : int | None = None ,
6968) -> SubsectionVersion :
@@ -78,17 +77,15 @@ def create_subsection_version(
7877 subsection_pk: The subsection ID.
7978 version_num: The version number.
8079 title: The title.
81- publishable_entities_pk: The publishable entities.
82- entity: The entity.
80+ entity_rows: child entities/versions
8381 created: The creation date.
8482 created_by: The user who created the subsection.
8583 """
8684 return publishing_api .create_container_version (
8785 subsection .pk ,
8886 version_num ,
8987 title = title ,
90- publishable_entities_pks = publishable_entities_pks ,
91- entity_version_pks = entity_version_pks ,
88+ entity_rows = entity_rows ,
9289 created = created ,
9390 created_by = created_by ,
9491 container_version_cls = SubsectionVersion ,
@@ -97,30 +94,33 @@ def create_subsection_version(
9794
9895def _pub_entities_for_units (
9996 units : list [Unit | UnitVersion ] | None ,
100- ) -> tuple [ list [int ], list [ int | None ]] | tuple [ None , None ] :
97+ ) -> list [publishing_api . ContainerEntityRow ] | None :
10198 """
10299 Helper method: given a list of Unit | UnitVersion, return the
103- lists of publishable_entities_pks and entity_version_pks needed for the
104- base container APIs.
100+ list of ContainerEntityRows needed for the base container APIs.
105101
106102 UnitVersion is passed when we want to pin a specific version, otherwise
107103 Unit is used for unpinned.
108104 """
109105 if units is None :
110106 # When these are None, that means don't change the entities in the list.
111- return None , None
107+ return None
112108 for u in units :
113109 if not isinstance (u , (Unit , UnitVersion )):
114110 raise TypeError ("Subsection units must be either Unit or UnitVersion." )
115- publishable_entities_pks = [
116- (u .publishable_entity_id if isinstance (u , Unit ) else u .unit .publishable_entity_id )
111+ return [
112+ (
113+ publishing_api .ContainerEntityRow (
114+ entity_pk = u .container .publishable_entity_id ,
115+ version_pk = None ,
116+ ) if isinstance (u , Unit )
117+ else publishing_api .ContainerEntityRow (
118+ entity_pk = u .unit .container .publishable_entity_id ,
119+ version_pk = u .container_version .publishable_entity_version_id ,
120+ )
121+ )
117122 for u in units
118123 ]
119- entity_version_pks = [
120- (uv .pk if isinstance (uv , UnitVersion ) else None )
121- for uv in units
122- ]
123- return publishable_entities_pks , entity_version_pks
124124
125125
126126def create_next_subsection_version (
@@ -143,12 +143,11 @@ def create_next_subsection_version(
143143 created: The creation date.
144144 created_by: The user who created the subsection.
145145 """
146- publishable_entities_pks , entity_version_pks = _pub_entities_for_units (units )
146+ entity_rows = _pub_entities_for_units (units )
147147 subsection_version = publishing_api .create_next_container_version (
148148 subsection .pk ,
149149 title = title ,
150- publishable_entities_pks = publishable_entities_pks ,
151- entity_version_pks = entity_version_pks ,
150+ entity_rows = entity_rows ,
152151 created = created ,
153152 created_by = created_by ,
154153 container_version_cls = SubsectionVersion ,
@@ -177,7 +176,7 @@ def create_subsection_and_version(
177176 created_by: The user who created the subsection.
178177 can_stand_alone: Set to False when created as part of containers
179178 """
180- publishable_entities_pks , entity_version_pks = _pub_entities_for_units (units )
179+ entity_rows = _pub_entities_for_units (units )
181180 with atomic ():
182181 subsection = create_subsection (
183182 learning_package_id ,
@@ -190,8 +189,7 @@ def create_subsection_and_version(
190189 subsection ,
191190 1 ,
192191 title = title ,
193- publishable_entities_pks = publishable_entities_pks or [],
194- entity_version_pks = entity_version_pks or [],
192+ entity_rows = entity_rows or [],
195193 created = created ,
196194 created_by = created_by ,
197195 )
@@ -286,7 +284,9 @@ def get_units_in_published_subsection_as_of(
286284 ancestors of every modified PublishableEntity in the publish.
287285 """
288286 assert isinstance (subsection , Subsection )
289- subsection_pub_entity_version = publishing_api .get_published_version_as_of (subsection .publishable_entity_id , publish_log_id )
287+ subsection_pub_entity_version = publishing_api .get_published_version_as_of (
288+ subsection .publishable_entity_id , publish_log_id
289+ )
290290 if subsection_pub_entity_version is None :
291291 return None # This subsection was not published as of the given PublishLog ID.
292292 container_version = subsection_pub_entity_version .containerversion
@@ -303,5 +303,7 @@ def get_units_in_published_subsection_as_of(
303303 # This is not optimized. It could be done in one query per subsection rather than one query per unit.
304304 pub_entity_version = publishing_api .get_published_version_as_of (row .entity_id , publish_log_id )
305305 if pub_entity_version :
306- entity_list .append (SubsectionListEntry (unit_version = pub_entity_version .containerversion .unitversion , pinned = False ))
306+ entity_list .append (
307+ SubsectionListEntry (unit_version = pub_entity_version .containerversion .unitversion , pinned = False )
308+ )
307309 return entity_list
0 commit comments