Skip to content
Closed
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
3 changes: 3 additions & 0 deletions openedx/core/djangoapps/content_libraries/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@
from .constants import ALL_RIGHTS_RESERVED
from .models import ContentLibrary, ContentLibraryPermission, ContentLibraryBlockImportTask

# Import Units API Module for use when importing the content_libraries API module
from .units.api import *

log = logging.getLogger(__name__)


Expand Down
3 changes: 3 additions & 0 deletions openedx/core/djangoapps/content_libraries/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
CC_4_BY_ND = 'CC:4.0:BY:ND'
CC_4_BY_SA = 'CC:4.0:BY:SA'

# Container types
CONTAINER_UNIT_TYPE = 'unit'

LICENSE_OPTIONS = (
(ALL_RIGHTS_RESERVED, _('All Rights Reserved.')),
(CC_4_BY, _('Creative Commons Attribution 4.0')),
Expand Down
Empty file.
30 changes: 30 additions & 0 deletions openedx/core/djangoapps/content_libraries/units/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
Python API for units in content libraries
================================

Via ``views.py``, most of these API methods are also exposed as a REST API.

The API methods in this file are focused on authoring and specific to units
in content libraries.

To import this API methods you can use:

from openedx.core.djangoapps.content_libraries import api as library_api

"""
from __future__ import annotations

from opaque_keys.edx.locator import LibraryLocatorV2, LibraryContainerLocator

from ..constants import CONTAINER_UNIT_TYPE


def get_library_unit_usage_key(
library_key: LibraryLocatorV2,
unit_key: str,
) -> LibraryContainerLocator:
"""
Returns the LibraryContainerLocator associated to a Unit.
"""

return LibraryContainerLocator(library_key, CONTAINER_UNIT_TYPE, unit_key)
Empty file.
26 changes: 26 additions & 0 deletions openedx/core/djangoapps/content_libraries/units/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
Tests for Units internal api.
"""
from django.test import TestCase

from opaque_keys.edx.locator import LibraryLocatorV2, LibraryContainerLocator

from .. import api

class UnitLibraryTest(TestCase):

library_key_str = 'lib:foobar_content:foobar_library'

def test_get_library_unit_usage_key(self):
"""
Test build the unit usage key
"""
library_key = LibraryLocatorV2.from_string(self.library_key_str)
unit_id = 'test-unit'
expected_key = f'lct:{library_key.org}:{library_key.slug}:unit:{unit_id}'

unit_key = api.get_library_unit_usage_key(library_key, unit_id)

assert unit_key.library_key == library_key
assert unit_key.container_id == unit_id
assert str(unit_key) == expected_key
4 changes: 2 additions & 2 deletions openedx/core/djangoapps/content_tagging/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import openedx_tagging.core.tagging.api as oel_tagging
from django.db.models import Exists, OuterRef, Q, QuerySet
from django.utils.timezone import now
from opaque_keys.edx.keys import CourseKey, LibraryCollectionKey
from opaque_keys.edx.keys import CourseKey, LibraryElementKey
from opaque_keys.edx.locator import LibraryLocatorV2
from openedx_tagging.core.tagging.models import ObjectTag, Taxonomy
from openedx_tagging.core.tagging.models.utils import TAGS_CSV_SEPARATOR
Expand Down Expand Up @@ -230,7 +230,7 @@ def generate_csv_rows(object_id, buffer) -> Iterator[str]:
"""
content_key = get_content_key_from_string(object_id)

if isinstance(content_key, (UsageKey, LibraryCollectionKey)):
if isinstance(content_key, (UsageKey, LibraryElementKey)):
raise ValueError("The object_id must be a CourseKey or a LibraryLocatorV2.")

all_object_tags, taxonomies = get_all_object_tags(content_key)
Expand Down
6 changes: 3 additions & 3 deletions openedx/core/djangoapps/content_tagging/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import ddt
from django.test.testcases import TestCase
from fs.osfs import OSFS
from opaque_keys.edx.keys import CourseKey, UsageKey, LibraryCollectionKey
from opaque_keys.edx.locator import LibraryLocatorV2
from opaque_keys.edx.keys import CourseKey, UsageKey
from opaque_keys.edx.locator import LibraryLocatorV2, LibraryCollectionLocator
from openedx_tagging.core.tagging.models import ObjectTag
from organizations.models import Organization
from .test_objecttag_export_helpers import TestGetAllObjectTagsMixin, TaggedCourseMixin
Expand Down Expand Up @@ -381,7 +381,7 @@ def test_copy_cross_org_tags(self):
self._test_copy_object_tags(src_key, dst_key, expected_tags)

def test_tag_collection(self):
collection_key = LibraryCollectionKey.from_string("lib-collection:orgA:libX:1")
collection_key = LibraryCollectionLocator.from_string("lib-collection:orgA:libX:1")

api.tag_object(
object_id=str(collection_key),
Expand Down
4 changes: 2 additions & 2 deletions openedx/core/djangoapps/content_tagging/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

from typing import Dict, List, Union

from opaque_keys.edx.keys import CourseKey, UsageKey, LibraryCollectionKey
from opaque_keys.edx.keys import CourseKey, UsageKey, LibraryElementKey
from opaque_keys.edx.locator import LibraryLocatorV2
from openedx_tagging.core.tagging.models import Taxonomy

ContentKey = Union[LibraryLocatorV2, CourseKey, UsageKey, LibraryCollectionKey]
ContentKey = Union[LibraryLocatorV2, CourseKey, UsageKey, LibraryElementKey]
ContextKey = Union[LibraryLocatorV2, CourseKey]

TagValuesByTaxonomyIdDict = Dict[int, List[str]]
Expand Down
10 changes: 5 additions & 5 deletions openedx/core/djangoapps/content_tagging/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from edx_django_utils.cache import RequestCache
from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import CourseKey, UsageKey, LibraryCollectionKey
from opaque_keys.edx.keys import CourseKey, UsageKey, LibraryElementKey
from opaque_keys.edx.locator import LibraryLocatorV2
from openedx_tagging.core.tagging.models import Taxonomy
from organizations.models import Organization
Expand All @@ -28,11 +28,11 @@ def get_content_key_from_string(key_str: str) -> ContentKey:
return UsageKey.from_string(key_str)
except InvalidKeyError:
try:
return LibraryCollectionKey.from_string(key_str)
return LibraryElementKey.from_string(key_str)
except InvalidKeyError as usage_key_error:
raise ValueError(
"object_id must be one of the following "
"keys: CourseKey, LibraryLocatorV2, UsageKey or LibCollectionKey"
"keys: CourseKey, LibraryLocatorV2, UsageKey or LibraryElementKey"
) from usage_key_error


Expand All @@ -44,8 +44,8 @@ def get_context_key_from_key(content_key: ContentKey) -> ContextKey:
if isinstance(content_key, (CourseKey, LibraryLocatorV2)):
return content_key

# If the content key is a LibraryCollectionKey, return the LibraryLocatorV2
if isinstance(content_key, LibraryCollectionKey):
# If the content key is a LibraryElementKey, return the LibraryLocatorV2
if isinstance(content_key, LibraryElementKey):
return content_key.library_key

# If the content key is a UsageKey, return the context key
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ edx-milestones==0.6.0
# via -r requirements/edx/kernel.in
edx-name-affirmation==3.0.1
# via -r requirements/edx/kernel.in
edx-opaque-keys[django]==2.11.0
edx-opaque-keys[django] @ git+https://github.com/open-craft/opaque-keys.git@chris/FAL-4108-create-container-keys
# via
# -r requirements/edx/kernel.in
# edx-bulk-grades
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ edx-name-affirmation==3.0.1
# via
# -r requirements/edx/doc.txt
# -r requirements/edx/testing.txt
edx-opaque-keys[django]==2.11.0
edx-opaque-keys[django] @ git+https://github.com/open-craft/opaque-keys.git@chris/FAL-4108-create-container-keys
# via
# -r requirements/edx/doc.txt
# -r requirements/edx/testing.txt
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ edx-milestones==0.6.0
# via -r requirements/edx/base.txt
edx-name-affirmation==3.0.1
# via -r requirements/edx/base.txt
edx-opaque-keys[django]==2.11.0
edx-opaque-keys[django] @ git+https://github.com/open-craft/opaque-keys.git@chris/FAL-4108-create-container-keys
# via
# -r requirements/edx/base.txt
# edx-bulk-grades
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/kernel.in
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ edx-event-bus-kafka>=5.6.0 # Kafka implementation of event bus
edx-event-bus-redis
edx-milestones
edx-name-affirmation
edx-opaque-keys
git+https://github.com/open-craft/opaque-keys.git@chris/FAL-4108-create-container-keys#egg=edx-opaque-keys
edx-organizations
edx-proctoring>=2.0.1
# using hash to support django42
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ edx-milestones==0.6.0
# via -r requirements/edx/base.txt
edx-name-affirmation==3.0.1
# via -r requirements/edx/base.txt
edx-opaque-keys[django]==2.11.0
edx-opaque-keys[django] @ git+https://github.com/open-craft/opaque-keys.git@chris/FAL-4108-create-container-keys
# via
# -r requirements/edx/base.txt
# edx-bulk-grades
Expand Down
Loading