1212from openedx_learning .apps .authoring .publishing .models .learning_package import LearningPackage
1313
1414
15- def toml_learning_package (learning_package : LearningPackage ) -> str :
15+ def toml_learning_package (learning_package : LearningPackage , timestamp : datetime ) -> str :
1616 """
1717 Create a TOML representation of the learning package.
1818
@@ -27,7 +27,7 @@ def toml_learning_package(learning_package: LearningPackage) -> str:
2727 updated = 2025-09-03T17:50:59.536190Z
2828 """
2929 doc = tomlkit .document ()
30- doc .add (tomlkit .comment (f"Datetime of the export: { datetime . now () } " ))
30+ doc .add (tomlkit .comment (f"Datetime of the export: { timestamp } " ))
3131 section = tomlkit .table ()
3232 section .add ("title" , learning_package .title )
3333 section .add ("key" , learning_package .key )
@@ -40,6 +40,8 @@ def toml_learning_package(learning_package: LearningPackage) -> str:
4040
4141def _get_toml_publishable_entity_table (
4242 entity : PublishableEntity ,
43+ draft_version : PublishableEntityVersion | None ,
44+ published_version : PublishableEntityVersion | None ,
4345 include_versions : bool = True ) -> tomlkit .items .Table :
4446 """
4547 Create a TOML representation of a publishable entity.
@@ -64,28 +66,30 @@ def _get_toml_publishable_entity_table(
6466 entity_table .add ("can_stand_alone" , entity .can_stand_alone )
6567 # Add key since the toml filename doesn't show the real key
6668 entity_table .add ("key" , entity .key )
69+ entity_table .add ("created" , entity .created )
6770
6871 if not include_versions :
6972 return entity_table
7073
71- current_draft_version = publishing_api .get_draft_version (entity )
72- current_published_version = publishing_api .get_published_version (entity )
73-
74- if current_draft_version :
74+ if draft_version :
7575 draft_table = tomlkit .table ()
76- draft_table .add ("version_num" , current_draft_version .version_num )
76+ draft_table .add ("version_num" , draft_version .version_num )
7777 entity_table .add ("draft" , draft_table )
7878
7979 published_table = tomlkit .table ()
80- if current_published_version :
81- published_table .add ("version_num" , current_published_version .version_num )
80+ if published_version :
81+ published_table .add ("version_num" , published_version .version_num )
8282 else :
8383 published_table .add (tomlkit .comment ("unpublished: no published_version_num" ))
8484 entity_table .add ("published" , published_table )
8585 return entity_table
8686
8787
88- def toml_publishable_entity (entity : PublishableEntity , versions_to_write : list [PublishableEntityVersion ]) -> str :
88+ def toml_publishable_entity (
89+ entity : PublishableEntity ,
90+ versions_to_write : list [PublishableEntityVersion ],
91+ draft_version : PublishableEntityVersion | None ,
92+ published_version : PublishableEntityVersion | None ) -> str :
8993 """
9094 Create a TOML representation of a publishable entity and its versions.
9195
@@ -114,7 +118,7 @@ def toml_publishable_entity(entity: PublishableEntity, versions_to_write: list[P
114118 [version.container.unit]
115119 graded = true
116120 """
117- entity_table = _get_toml_publishable_entity_table (entity )
121+ entity_table = _get_toml_publishable_entity_table (entity , draft_version , published_version )
118122 doc = tomlkit .document ()
119123 doc .add ("entity" , entity_table )
120124 doc .add (tomlkit .nl ())
@@ -152,16 +156,22 @@ def toml_publishable_entity_version(version: PublishableEntityVersion) -> tomlki
152156 version_table .add ("title" , version .title )
153157 version_table .add ("uuid" , str (version .uuid ))
154158 version_table .add ("version_num" , version .version_num )
159+
155160 container_table = tomlkit .table ()
156- container_table .add ("children" , [])
161+
162+ children = []
163+ if hasattr (version , 'containerversion' ):
164+ children = publishing_api .get_container_children_entities_keys (version .containerversion )
165+ container_table .add ("children" , children )
166+
157167 unit_table = tomlkit .table ()
158- unit_table . add ( "graded" , True )
168+
159169 container_table .add ("unit" , unit_table )
160170 version_table .add ("container" , container_table )
161171 return version_table # For use in AoT
162172
163173
164- def toml_collection (collection : Collection ) -> str :
174+ def toml_collection (collection : Collection , entity_keys : list [ str ] ) -> str :
165175 """
166176 Create a TOML representation of a collection.
167177
@@ -178,7 +188,6 @@ def toml_collection(collection: Collection) -> str:
178188 """
179189 doc = tomlkit .document ()
180190
181- entity_keys = collection .entities .order_by ("key" ).values_list ("key" , flat = True )
182191 entities_array = tomlkit .array ()
183192 entities_array .extend (entity_keys )
184193 entities_array .multiline (True )
0 commit comments