Skip to content

Commit d125b04

Browse files
ChrisChVbradenmacdonald
authored andcommitted
refactor: Use LibraryElementKey instead of LibraryCollectionKey
1 parent 144ff01 commit d125b04

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

openedx/core/djangoapps/content_tagging/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import openedx_tagging.core.tagging.api as oel_tagging
1313
from django.db.models import Exists, OuterRef, Q, QuerySet
1414
from django.utils.timezone import now
15-
from opaque_keys.edx.keys import CourseKey, LibraryCollectionKey
15+
from opaque_keys.edx.keys import CourseKey, LibraryElementKey
1616
from opaque_keys.edx.locator import LibraryLocatorV2
1717
from openedx_tagging.core.tagging.models import ObjectTag, Taxonomy
1818
from openedx_tagging.core.tagging.models.utils import TAGS_CSV_SEPARATOR
@@ -230,7 +230,7 @@ def generate_csv_rows(object_id, buffer) -> Iterator[str]:
230230
"""
231231
content_key = get_content_key_from_string(object_id)
232232

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

236236
all_object_tags, taxonomies = get_all_object_tags(content_key)

openedx/core/djangoapps/content_tagging/tests/test_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import ddt
66
from django.test.testcases import TestCase
77
from fs.osfs import OSFS
8-
from opaque_keys.edx.keys import CourseKey, UsageKey, LibraryCollectionKey
9-
from opaque_keys.edx.locator import LibraryLocatorV2
8+
from opaque_keys.edx.keys import CourseKey, UsageKey
9+
from opaque_keys.edx.locator import LibraryLocatorV2, LibraryCollectionLocator
1010
from openedx_tagging.core.tagging.models import ObjectTag
1111
from organizations.models import Organization
1212
from .test_objecttag_export_helpers import TestGetAllObjectTagsMixin, TaggedCourseMixin
@@ -381,7 +381,7 @@ def test_copy_cross_org_tags(self):
381381
self._test_copy_object_tags(src_key, dst_key, expected_tags)
382382

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

386386
api.tag_object(
387387
object_id=str(collection_key),

openedx/core/djangoapps/content_tagging/types.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
from typing import Dict, List, Union
77

8-
from opaque_keys.edx.keys import CourseKey, UsageKey, LibraryCollectionKey
8+
from opaque_keys.edx.keys import CourseKey, UsageKey, LibraryElementKey
99
from opaque_keys.edx.locator import LibraryLocatorV2
1010
from openedx_tagging.core.tagging.models import Taxonomy
1111

12-
ContentKey = Union[LibraryLocatorV2, CourseKey, UsageKey, LibraryCollectionKey]
12+
ContentKey = Union[LibraryLocatorV2, CourseKey, UsageKey, LibraryElementKey]
1313
ContextKey = Union[LibraryLocatorV2, CourseKey]
1414

1515
TagValuesByTaxonomyIdDict = Dict[int, List[str]]

openedx/core/djangoapps/content_tagging/utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from edx_django_utils.cache import RequestCache
77
from opaque_keys import InvalidKeyError
8-
from opaque_keys.edx.keys import CourseKey, UsageKey, LibraryCollectionKey
8+
from opaque_keys.edx.keys import CourseKey, UsageKey, LibraryElementKey
99
from opaque_keys.edx.locator import LibraryLocatorV2
1010
from openedx_tagging.core.tagging.models import Taxonomy
1111
from organizations.models import Organization
@@ -28,11 +28,11 @@ def get_content_key_from_string(key_str: str) -> ContentKey:
2828
return UsageKey.from_string(key_str)
2929
except InvalidKeyError:
3030
try:
31-
return LibraryCollectionKey.from_string(key_str)
31+
return LibraryElementKey.from_string(key_str)
3232
except InvalidKeyError as usage_key_error:
3333
raise ValueError(
3434
"object_id must be one of the following "
35-
"keys: CourseKey, LibraryLocatorV2, UsageKey or LibCollectionKey"
35+
"keys: CourseKey, LibraryLocatorV2, UsageKey or LibraryElementKey"
3636
) from usage_key_error
3737

3838

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

47-
# If the content key is a LibraryCollectionKey, return the LibraryLocatorV2
48-
if isinstance(content_key, LibraryCollectionKey):
47+
# If the content key is a LibraryElementKey, return the LibraryLocatorV2
48+
if isinstance(content_key, LibraryElementKey):
4949
return content_key.library_key
5050

5151
# If the content key is a UsageKey, return the context key

0 commit comments

Comments
 (0)