|
37 | 37 | LIBRARY_CONTAINER_UPDATED |
38 | 38 | ) |
39 | 39 | from openedx_learning.api import authoring as authoring_api |
40 | | -from openedx_learning.api.authoring_models import Component, ComponentVersion, LearningPackage, MediaType |
| 40 | +from openedx_learning.api.authoring_models import ( |
| 41 | + Component, ComponentVersion, LearningPackage, MediaType, |
| 42 | + Container, Collection |
| 43 | +) |
41 | 44 | from xblock.core import XBlock |
42 | 45 |
|
43 | 46 | from openedx.core.djangoapps.xblock.api import ( |
|
80 | 83 | __all__ = [ |
81 | 84 | # API methods |
82 | 85 | "get_library_components", |
| 86 | + "get_library_containers", |
| 87 | + "get_library_collections", |
83 | 88 | "get_library_block", |
84 | 89 | "set_library_block_olx", |
85 | 90 | "get_component_from_usage_key", |
@@ -121,6 +126,33 @@ def get_library_components( |
121 | 126 | return components |
122 | 127 |
|
123 | 128 |
|
| 129 | +def get_library_containers(library_key: LibraryLocatorV2) -> QuerySet[Container]: |
| 130 | + """ |
| 131 | + Get all containers in the given content library. |
| 132 | + """ |
| 133 | + lib = ContentLibrary.objects.get_by_key(library_key) # type: ignore[attr-defined] |
| 134 | + learning_package = lib.learning_package |
| 135 | + assert learning_package is not None |
| 136 | + containers: QuerySet[Container] = authoring_api.get_containers( |
| 137 | + learning_package.id |
| 138 | + ) |
| 139 | + |
| 140 | + return containers |
| 141 | + |
| 142 | + |
| 143 | +def get_library_collections(library_key: LibraryLocatorV2) -> QuerySet[Collection]: |
| 144 | + """ |
| 145 | + Get all collections in the given content library. |
| 146 | + """ |
| 147 | + lib = ContentLibrary.objects.get_by_key(library_key) # type: ignore[attr-defined] |
| 148 | + learning_package = lib.learning_package |
| 149 | + assert learning_package is not None |
| 150 | + collections = authoring_api.get_collections( |
| 151 | + learning_package.id |
| 152 | + ) |
| 153 | + return collections |
| 154 | + |
| 155 | + |
124 | 156 | def get_library_block(usage_key: LibraryUsageLocatorV2, include_collections=False) -> LibraryXBlockMetadata: |
125 | 157 | """ |
126 | 158 | Get metadata about (the draft version of) one specific XBlock in a library. |
|
0 commit comments