Skip to content
Merged
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 @@ -48,10 +48,7 @@ def from_component(cls, library_key, component, associated_collections=None):
tags = get_object_tag_counts(str(usage_key), count_implicit=True)

return cls(
usage_key=library_component_usage_key(
library_key,
component,
),
usage_key=usage_key,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh thank you for spotting this!

display_name=draft.title,
created=component.created,
modified=draft.created,
Expand Down
3 changes: 3 additions & 0 deletions openedx/core/djangoapps/content_libraries/api/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from openedx_learning.api import authoring as authoring_api
from openedx_learning.api.authoring_models import Container, ContainerVersion, Component
from openedx.core.djangoapps.content_libraries.api.collections import library_collection_locator
from openedx.core.djangoapps.content_tagging.api import get_object_tag_counts

from openedx.core.djangoapps.xblock.api import get_component_from_usage_key

Expand Down Expand Up @@ -132,6 +133,7 @@ def from_container(cls, library_key, container: Container, associated_collection
last_draft_created_by = draft.publishable_entity_version.created_by.username
else:
last_draft_created_by = ""
tags = get_object_tag_counts(str(container_key), count_implicit=True)

return cls(
container_key=container_key,
Expand All @@ -148,6 +150,7 @@ def from_container(cls, library_key, container: Container, associated_collection
last_draft_created=last_draft_created,
last_draft_created_by=last_draft_created_by,
has_unpublished_changes=authoring_api.contains_unpublished_changes(container.pk),
tags_count=tags.get(str(container_key), 0),
collections=associated_collections or [],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ class LibraryContainerChildrenView(GenericAPIView):

@convert_exceptions
@swagger_auto_schema(
responses={200: list[serializers.LibraryXBlockMetadataSerializer]}
responses={
200: list[serializers.LibraryXBlockMetadataSerializer]
| list[serializers.LibraryContainerMetadataSerializer]
}
)
def get(self, request, container_key: LibraryContainerLocator):
"""
Expand Down
26 changes: 26 additions & 0 deletions openedx/core/djangoapps/content_libraries/tests/test_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from common.djangoapps.student.tests.factories import UserFactory
from openedx.core.djangoapps.content_libraries import api
from openedx.core.djangoapps.content_libraries.tests.base import ContentLibrariesRestApiTest
from openedx.core.djangoapps.content_tagging import api as tagging_api
from openedx.core.djangolib.testing.utils import skip_unless_cms


Expand Down Expand Up @@ -45,6 +46,13 @@ def setUp(self) -> None:
)
self.lib_key = LibraryLocatorV2.from_string(self.lib["id"])

self.taxonomy = tagging_api.create_taxonomy('New Taxonomy')
tagging_api.set_taxonomy_orgs(self.taxonomy, all_orgs=True)
tagging_api.add_tag_to_taxonomy(self.taxonomy, "one")
tagging_api.add_tag_to_taxonomy(self.taxonomy, "two")
tagging_api.add_tag_to_taxonomy(self.taxonomy, "three")
tagging_api.add_tag_to_taxonomy(self.taxonomy, "four")

# Create containers
with freeze_time(self.create_date):
# Unit
Expand Down Expand Up @@ -543,6 +551,24 @@ def test_restore_containers(self, container_type) -> None:

self.assertDictContainsEntries(new_container_data, expected_data)

@ddt.data(
"unit",
"subsection",
"section",
)
def test_tag_containers(self, container_type) -> None:
container = getattr(self, container_type)

assert container["tags_count"] == 0
tagging_api.tag_object(
container["id"],
self.taxonomy,
['one', 'three', 'four'],
)

new_container_data = self._get_container(container["id"])
assert new_container_data["tags_count"] == 3

def test_container_collections(self) -> None:
# Create a collection
col1 = api.create_library_collection(
Expand Down
Loading