@@ -62,8 +62,7 @@ def create_section_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) -> SectionVersion :
@@ -78,17 +77,15 @@ def create_section_version(
7877 section_pk: The section 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 section.
8583 """
8684 return publishing_api .create_container_version (
8785 section .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 = SectionVersion ,
@@ -97,7 +94,7 @@ def create_section_version(
9794
9895def _pub_entities_for_subsections (
9996 subsections : list [Subsection | SubsectionVersion ] | 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 Subsection | SubsectionVersion, return the
103100 lists of publishable_entities_pks and entity_version_pks needed for the
@@ -108,19 +105,23 @@ def _pub_entities_for_subsections(
108105 """
109106 if subsections is None :
110107 # When these are None, that means don't change the entities in the list.
111- return None , None
108+ return None
112109 for u in subsections :
113110 if not isinstance (u , (Subsection , SubsectionVersion )):
114111 raise TypeError ("Section subsections must be either Subsection or SubsectionVersion." )
115- publishable_entities_pks = [
116- (u .publishable_entity_id if isinstance (u , Subsection ) else u .subsection .publishable_entity_id )
117- for u in subsections
118- ]
119- entity_version_pks = [
120- (uv .pk if isinstance (uv , SubsectionVersion ) else None )
121- for uv in subsections
112+ return [
113+ (
114+ publishing_api .ContainerEntityRow (
115+ entity_pk = s .container .publishable_entity_id ,
116+ version_pk = None ,
117+ ) if isinstance (s , Subsection )
118+ else publishing_api .ContainerEntityRow (
119+ entity_pk = s .subsection .container .publishable_entity_id ,
120+ version_pk = s .container_version .publishable_entity_version_id ,
121+ )
122+ )
123+ for s in subsections
122124 ]
123- return publishable_entities_pks , entity_version_pks
124125
125126
126127def create_next_section_version (
@@ -138,17 +139,16 @@ def create_next_section_version(
138139 Args:
139140 section_pk: The section ID.
140141 title: The title. Leave as None to keep the current title.
141- subsections: The subsections, as a list of Subsections (unpinned) and/or SubsectionVersions (pinned). Passing None
142- will leave the existing subsections unchanged.
142+ subsections: The subsections, as a list of Subsections (unpinned) and/or SubsectionVersions (pinned).
143+ Passing None will leave the existing subsections unchanged.
143144 created: The creation date.
144145 created_by: The user who created the section.
145146 """
146- publishable_entities_pks , entity_version_pks = _pub_entities_for_subsections (subsections )
147+ entity_rows = _pub_entities_for_subsections (subsections )
147148 section_version = publishing_api .create_next_container_version (
148149 section .pk ,
149150 title = title ,
150- publishable_entities_pks = publishable_entities_pks ,
151- entity_version_pks = entity_version_pks ,
151+ entity_rows = entity_rows ,
152152 created = created ,
153153 created_by = created_by ,
154154 container_version_cls = SectionVersion ,
@@ -177,7 +177,7 @@ def create_section_and_version(
177177 created_by: The user who created the section.
178178 can_stand_alone: Set to False when created as part of containers
179179 """
180- publishable_entities_pks , entity_version_pks = _pub_entities_for_subsections (subsections )
180+ entity_rows = _pub_entities_for_subsections (subsections )
181181 with atomic ():
182182 section = create_section (
183183 learning_package_id ,
@@ -190,8 +190,7 @@ def create_section_and_version(
190190 section ,
191191 1 ,
192192 title = title ,
193- publishable_entities_pks = publishable_entities_pks or [],
194- entity_version_pks = entity_version_pks or [],
193+ entity_rows = entity_rows or [],
195194 created = created ,
196195 created_by = created_by ,
197196 )
@@ -286,7 +285,9 @@ def get_subsections_in_published_section_as_of(
286285 ancestors of every modified PublishableEntity in the publish.
287286 """
288287 assert isinstance (section , Section )
289- section_pub_entity_version = publishing_api .get_published_version_as_of (section .publishable_entity_id , publish_log_id )
288+ section_pub_entity_version = publishing_api .get_published_version_as_of (
289+ section .publishable_entity_id , publish_log_id
290+ )
290291 if section_pub_entity_version is None :
291292 return None # This section was not published as of the given PublishLog ID.
292293 container_version = section_pub_entity_version .containerversion
@@ -303,5 +304,7 @@ def get_subsections_in_published_section_as_of(
303304 # This is not optimized. It could be done in one query per section rather than one query per subsection.
304305 pub_entity_version = publishing_api .get_published_version_as_of (row .entity_id , publish_log_id )
305306 if pub_entity_version :
306- entity_list .append (SectionListEntry (subsection_version = pub_entity_version .containerversion .subsectionversion , pinned = False ))
307+ entity_list .append (SectionListEntry (
308+ subsection_version = pub_entity_version .containerversion .subsectionversion , pinned = False
309+ ))
307310 return entity_list
0 commit comments