feat: Add tags_count to ContainerMetadata (#36883)
This commit is contained in:
@@ -48,10 +48,7 @@ class LibraryXBlockMetadata(PublishableItem):
|
||||
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,
|
||||
display_name=draft.title,
|
||||
created=component.created,
|
||||
modified=draft.created,
|
||||
|
||||
@@ -26,6 +26,7 @@ from openedx_events.content_authoring.signals import (
|
||||
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
|
||||
|
||||
@@ -132,6 +133,7 @@ class ContainerMetadata(PublishableItem):
|
||||
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,
|
||||
@@ -148,6 +150,7 @@ class ContainerMetadata(PublishableItem):
|
||||
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 [],
|
||||
)
|
||||
|
||||
|
||||
@@ -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):
|
||||
"""
|
||||
|
||||
@@ -11,6 +11,7 @@ from opaque_keys.edx.locator import LibraryLocatorV2
|
||||
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
|
||||
|
||||
|
||||
@@ -45,6 +46,13 @@ class ContainersTestCase(ContentLibrariesRestApiTest):
|
||||
)
|
||||
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
|
||||
@@ -543,6 +551,24 @@ class ContainersTestCase(ContentLibrariesRestApiTest):
|
||||
|
||||
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(
|
||||
|
||||
Reference in New Issue
Block a user