Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def setUp(self):
collection_key = "test-collection"
content_api.create_collection(
learning_package_id=learning_package.id,
key=collection_key,
collection_code=collection_key,
title="Test Collection",
created_by=self.user.id,
)
Expand Down
2 changes: 1 addition & 1 deletion cms/djangoapps/modulestore_migrator/api/read_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def _migration(m: models.ModulestoreMigration) -> ModulestoreMigration:
source_key=m.source.key,
target_key=LibraryLocatorV2.from_string(m.target.key),
target_title=m.target.title,
target_collection_slug=(m.target_collection.key if m.target_collection else None),
target_collection_slug=(m.target_collection.collection_code if m.target_collection else None),
target_collection_title=(m.target_collection.title if m.target_collection else None),
is_failed=m.is_failed,
task_uuid=m.task_status.uuid,
Expand Down
2 changes: 1 addition & 1 deletion cms/djangoapps/modulestore_migrator/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def _populate_collection(user_id: int, migration: models.ModulestoreMigration) -
if block_target_pks:
content_api.add_to_collection(
learning_package_id=migration.target.pk,
key=migration.target_collection.key,
collection_code=migration.target_collection.collection_code,
entities_qset=PublishableEntity.objects.filter(id__in=block_target_pks),
created_by=user_id,
)
Expand Down
10 changes: 5 additions & 5 deletions cms/djangoapps/modulestore_migrator/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def test_start_migration_to_library_with_collection(self):
collection_key = "test-collection"
content_api.create_collection(
learning_package_id=self.learning_package.id,
key=collection_key,
collection_code=collection_key,
title="Test Collection",
created_by=user.id,
)
Expand All @@ -249,7 +249,7 @@ def test_start_migration_to_library_with_collection(self):
)

modulestoremigration = ModulestoreMigration.objects.get()
assert modulestoremigration.target_collection.key == collection_key
assert modulestoremigration.target_collection.collection_code == collection_key

def test_start_migration_to_library_with_strategy_skip(self):
"""
Expand Down Expand Up @@ -487,19 +487,19 @@ def test_migration_api_for_various_scenarios(self):
# Lib 2 has Collection C
content_api.create_collection(
learning_package_id=self.learning_package.id,
key="test-collection-1a",
collection_code="test-collection-1a",
title="Test Collection A in Lib 1",
created_by=user.id,
)
content_api.create_collection(
learning_package_id=self.learning_package.id,
key="test-collection-1b",
collection_code="test-collection-1b",
title="Test Collection B in Lib 1",
created_by=user.id,
)
content_api.create_collection(
learning_package_id=self.learning_package_2.id,
key="test-collection-2c",
collection_code="test-collection-2c",
title="Test Collection C in Lib 2",
created_by=user.id,
)
Expand Down
4 changes: 2 additions & 2 deletions openedx/core/djangoapps/content/search/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ def index_collection_batch(batch, num_done, library_key) -> int:
docs = []
for collection in batch:
try:
collection_key = lib_api.library_collection_locator(library_key, collection.key)
collection_key = lib_api.library_collection_locator(library_key, collection.collection_code)
doc = searchable_doc_for_collection(collection_key, collection=collection)
doc.update(searchable_doc_tags(collection_key))
docs.append(doc)
Expand Down Expand Up @@ -898,7 +898,7 @@ def upsert_content_library_index_docs(library_key: LibraryLocatorV2, full_index:
docs.append(doc)

for collection in lib_api.get_library_collections(library_key):
collection_key = lib_api.library_collection_locator(library_key, collection.key)
collection_key = lib_api.library_collection_locator(library_key, collection.collection_code)
doc = searchable_doc_for_collection(collection_key, collection=collection)
docs.append(doc)

Expand Down
4 changes: 2 additions & 2 deletions openedx/core/djangoapps/content/search/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ def searchable_doc_for_collection(
pass

if collection:
assert collection.key == collection_key.collection_id
assert collection.collection_code == collection_key.collection_id

draft_num_children = content_api.filter_publishable_entities(
collection.entities,
Expand All @@ -558,7 +558,7 @@ def searchable_doc_for_collection(
Fields.context_key: str(collection_key.context_key),
Fields.org: str(collection_key.org),
Fields.usage_key: str(collection_key),
Fields.block_id: collection.key,
Fields.block_id: collection.collection_code,
Fields.type: DocType.collection,
Fields.display_name: collection.title,
Fields.description: collection.description,
Expand Down
18 changes: 9 additions & 9 deletions openedx/core/djangoapps/content/search/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def setUp(self) -> None:
with freeze_time(self.created_date):
self.collection = content_api.create_collection(
learning_package_id=self.learning_package.id,
key="MYCOL",
collection_code="MYCOL",
title="my_collection",
created_by=None,
description="my collection description"
Expand All @@ -204,7 +204,7 @@ def setUp(self) -> None:
)
self.collection_dict = {
"id": "lib-collectionorg1libmycol-5b647617",
"block_id": self.collection.key,
"block_id": self.collection.collection_code,
"usage_key": str(self.collection_key),
"type": "collection",
"display_name": "my_collection",
Expand Down Expand Up @@ -711,7 +711,7 @@ def test_index_library_block_and_collections(self, mock_meilisearch) -> None:
for collection in (collection2, collection1):
library_api.update_library_collection_items(
self.library.key,
collection_key=collection.key,
collection_key=collection.collection_code,
opaque_keys=[
self.problem1.usage_key,
],
Expand Down Expand Up @@ -893,7 +893,7 @@ def test_delete_collection(self, mock_meilisearch) -> None:
with freeze_time(updated_date):
library_api.update_library_collection_items(
self.library.key,
collection_key=self.collection.key,
collection_key=self.collection.collection_code,
opaque_keys=[
self.problem1.usage_key,
self.unit.container_key
Expand All @@ -907,14 +907,14 @@ def test_delete_collection(self, mock_meilisearch) -> None:
"id": self.doc_problem1["id"],
"collections": {
"display_name": [self.collection.title],
"key": [self.collection.key],
"key": [self.collection.collection_code],
},
}
doc_unit_with_collection = {
"id": self.unit_dict["id"],
"collections": {
"display_name": [self.collection.title],
"key": [self.collection.key],
"key": [self.collection.collection_code],
},
}

Expand All @@ -933,7 +933,7 @@ def test_delete_collection(self, mock_meilisearch) -> None:
# Soft-delete the collection
content_api.delete_collection(
self.collection.learning_package_id,
self.collection.key,
self.collection.collection_code,
)

doc_problem_without_collection = {
Expand Down Expand Up @@ -968,7 +968,7 @@ def test_delete_collection(self, mock_meilisearch) -> None:
with freeze_time(restored_date):
content_api.restore_collection(
self.collection.learning_package_id,
self.collection.key,
self.collection.collection_code,
)

doc_collection = copy.deepcopy(self.collection_dict)
Expand All @@ -990,7 +990,7 @@ def test_delete_collection(self, mock_meilisearch) -> None:
# Hard-delete the collection
content_api.delete_collection(
self.collection.learning_package_id,
self.collection.key,
self.collection.collection_code,
hard_delete=True,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def test_collection_with_library(self):

assert doc == {
"id": "lib-collectionedx2012_falltoy_collection-d1d907a4",
"block_id": self.collection.key,
"block_id": self.collection.collection_code,
"usage_key": str(self.collection_key),
"type": "collection",
"org": "edX",
Expand Down Expand Up @@ -521,7 +521,7 @@ def test_collection_with_published_library(self):

assert doc == {
"id": "lib-collectionedx2012_falltoy_collection-d1d907a4",
"block_id": self.collection.key,
"block_id": self.collection.collection_code,
"usage_key": str(self.collection_key),
"type": "collection",
"org": "edX",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
Content libraries data classes related to XBlocks/Components.
"""
from __future__ import annotations

import typing as t
from dataclasses import dataclass

from django.utils.translation import gettext as _
from opaque_keys.edx.locator import LibraryUsageLocatorV2
from openedx_content.models_api import Component

from .libraries import (
library_component_usage_key,
PublishableItem,
CollectionMetadata,
)

# The public API is only the following symbols:
Expand All @@ -26,7 +31,9 @@ class LibraryXBlockMetadata(PublishableItem):
usage_key: LibraryUsageLocatorV2

@classmethod
def from_component(cls, library_key, component, associated_collections=None):
def from_component(
cls, library_key, component: Component, associated_collections: list[CollectionMetadata] | None = None
) -> t.Self:
"""
Construct a LibraryXBlockMetadata from a Component object.
"""
Expand Down
4 changes: 2 additions & 2 deletions openedx/core/djangoapps/content_libraries/api/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ def delete_library_block(
library_collection=LibraryCollectionData(
collection_key=library_collection_locator(
library_key=library_key,
collection_key=collection.key,
collection_key=collection.collection_code,
),
background=True,
)
Expand Down Expand Up @@ -795,7 +795,7 @@ def restore_library_block(usage_key: LibraryUsageLocatorV2, user_id: int | None
library_collection=LibraryCollectionData(
collection_key=library_collection_locator(
library_key=library_key,
collection_key=collection.key,
collection_key=collection.collection_code,
),
background=True,
)
Expand Down
6 changes: 3 additions & 3 deletions openedx/core/djangoapps/content_libraries/api/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def create_library_collection(
try:
collection = content_api.create_collection(
learning_package_id=content_library.learning_package_id,
key=collection_key,
collection_code=collection_key,
title=title,
description=description,
created_by=created_by,
Expand Down Expand Up @@ -86,7 +86,7 @@ def update_library_collection(
try:
collection = content_api.update_collection(
learning_package_id=content_library.learning_package_id,
key=collection_key,
collection_code=collection_key,
title=title,
description=description,
)
Expand Down Expand Up @@ -232,7 +232,7 @@ def set_library_item_collections(
library_collection=LibraryCollectionData(
collection_key=library_collection_locator(
library_key=library_key,
collection_key=collection.key,
collection_key=collection.collection_code,
),
background=True,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from __future__ import annotations

import typing as t
from dataclasses import dataclass, field as dataclass_field
from enum import Enum
from django.db.models import QuerySet
Expand All @@ -25,7 +26,7 @@

from ..models import ContentLibrary
from .exceptions import ContentLibraryBlockNotFound, ContentLibraryContainerNotFound
from .libraries import PublishableItem, library_component_usage_key
from .libraries import PublishableItem, library_component_usage_key, CollectionMetadata

# The public API is only the following symbols:
__all__ = [
Expand Down Expand Up @@ -73,7 +74,9 @@ class ContainerMetadata(PublishableItem):
container_pk: int

@classmethod
def from_container(cls, library_key, container: Container, associated_collections=None):
def from_container(
cls, library_key, container: Container, associated_collections: list[CollectionMetadata] | None = None
) -> t.Self:
"""
Construct a ContainerMetadata object from a Container object.
"""
Expand Down
6 changes: 3 additions & 3 deletions openedx/core/djangoapps/content_libraries/api/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def get_container(
associated_collections = content_api.get_entity_collections(
container.publishable_entity.learning_package_id,
container_key.container_id,
).values("key", "title")
).values("collection_code", "title")
else:
associated_collections = None
container_meta = ContainerMetadata.from_container(
Expand Down Expand Up @@ -235,7 +235,7 @@ def delete_container(
library_collection=LibraryCollectionData(
collection_key=library_collection_locator(
library_key=library_key,
collection_key=collection.key,
collection_key=collection.collection_code,
),
background=True,
)
Expand Down Expand Up @@ -319,7 +319,7 @@ def restore_container(container_key: LibraryContainerLocator) -> None:
library_collection=LibraryCollectionData(
collection_key=library_collection_locator(
library_key=library_key,
collection_key=collection.key,
collection_key=collection.collection_code,
),
)
)
Expand Down
2 changes: 1 addition & 1 deletion openedx/core/djangoapps/content_libraries/api/libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class CollectionMetadata:
"""
Class to represent collection metadata in a content library.
"""
key: str
collection_code: str
title: str


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class LibraryCollectionsView(ModelViewSet):
"""

serializer_class = ContentLibraryCollectionSerializer
lookup_field = 'key'
lookup_field = 'collection_code'

def __init__(self, *args, **kwargs) -> None:
"""
Expand Down Expand Up @@ -154,7 +154,7 @@ def partial_update(self, request: RestRequest, *args, **kwargs) -> Response:
request.user,
authz_permissions.EDIT_LIBRARY_COLLECTION
)
collection_key = kwargs["key"]
collection_key = kwargs["collection_code"]

update_serializer = ContentLibraryCollectionUpdateSerializer(
data=request.data, partial=True
Expand Down Expand Up @@ -185,7 +185,7 @@ def destroy(self, request: RestRequest, *args, **kwargs) -> Response:
assert collection.learning_package_id
content_api.delete_collection(
collection.learning_package_id,
collection.key,
collection.collection_code,
hard_delete=False,
)
return Response(None, status=HTTP_204_NO_CONTENT)
Expand All @@ -203,7 +203,7 @@ def restore(self, request: RestRequest, *args, **kwargs) -> Response:
authz_permissions.EDIT_LIBRARY_COLLECTION
)
assert content_library.learning_package_id
collection_key = kwargs["key"]
collection_key = kwargs["collection_code"]
content_api.restore_collection(
content_library.learning_package_id,
collection_key,
Expand All @@ -224,7 +224,7 @@ def update_items(self, request: RestRequest, *args, **kwargs) -> Response:
request.user,
authz_permissions.EDIT_LIBRARY_COLLECTION
)
collection_key = kwargs["key"]
collection_key = kwargs["collection_code"]

serializer = ContentLibraryItemKeysSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ class CollectionMetadataSerializer(serializers.Serializer):
"""
Serializer for CollectionMetadata
"""
key = serializers.CharField()
collection_code = serializers.CharField()
key = serializers.CharField(source="collection_code") # back-compat
title = serializers.CharField()


Expand Down
Loading
Loading