1919 LIBRARY_CONTAINER_UPDATED ,
2020)
2121from openedx_learning .api import authoring as authoring_api
22- from openedx_learning .api import authoring_models
22+ from openedx_learning .api . authoring_models import Container
2323
2424from ..models import ContentLibrary
2525from .libraries import PublishableItem
2626
2727
2828# The public API is only the following symbols:
2929__all__ = [
30+ "ContentLibraryContainerNotFound" ,
3031 "ContainerMetadata" ,
3132 "ContainerType" ,
3233 "get_container" ,
3738]
3839
3940
41+ ContentLibraryContainerNotFound = Container .DoesNotExist
42+
43+
4044class ContainerType (Enum ):
4145 Unit = "unit"
4246
@@ -50,7 +54,7 @@ class ContainerMetadata(PublishableItem):
5054 container_type : ContainerType
5155
5256 @classmethod
53- def from_container (cls , library_key , container : authoring_models . Container , associated_collections = None ):
57+ def from_container (cls , library_key , container : Container , associated_collections = None ):
5458 """
5559 Construct a ContainerMetadata object from a Container object.
5660 """
@@ -92,7 +96,7 @@ def from_container(cls, library_key, container: authoring_models.Container, asso
9296
9397def library_container_locator (
9498 library_key : LibraryLocatorV2 ,
95- container : authoring_models . Container ,
99+ container : Container ,
96100) -> LibraryContainerLocator :
97101 """
98102 Returns a LibraryContainerLocator for the given library + container.
@@ -109,9 +113,11 @@ def library_container_locator(
109113 )
110114
111115
112- def get_container (container_key : LibraryContainerLocator ) -> ContainerMetadata :
116+ def _get_container (container_key : LibraryContainerLocator ) -> Container :
113117 """
114- Get a container (a Section, Subsection, or Unit).
118+ Internal method to fetch the Container object from its LibraryContainerLocator
119+
120+ Raises ContentLibraryContainerNotFound if no container found, or if the container has been soft deleted.
115121 """
116122 assert isinstance (container_key , LibraryContainerLocator )
117123 content_library = ContentLibrary .objects .get_by_key (container_key .library_key )
@@ -121,6 +127,16 @@ def get_container(container_key: LibraryContainerLocator) -> ContainerMetadata:
121127 learning_package .id ,
122128 key = container_key .container_id ,
123129 )
130+ if container and container .versioning .draft :
131+ return container
132+ raise ContentLibraryContainerNotFound
133+
134+
135+ def get_container (container_key : LibraryContainerLocator ) -> ContainerMetadata :
136+ """
137+ Get a container (a Section, Subsection, or Unit).
138+ """
139+ container = _get_container (container_key )
124140 container_meta = ContainerMetadata .from_container (container_key .library_key , container )
125141 assert container_meta .container_type .value == container_key .container_type
126142 return container_meta
@@ -181,15 +197,8 @@ def update_container(
181197 """
182198 Update a container (e.g. a Unit) title.
183199 """
184- assert isinstance (container_key , LibraryContainerLocator )
200+ container = _get_container (container_key )
185201 library_key = container_key .library_key
186- content_library = ContentLibrary .objects .get_by_key (library_key )
187- learning_package = content_library .learning_package
188- assert learning_package is not None
189- container = authoring_api .get_container_by_key (
190- learning_package .id ,
191- key = container_key .container_id ,
192- )
193202
194203 assert container .unit
195204 unit_version = authoring_api .create_next_unit_version (
0 commit comments