88
99from django .core .exceptions import ObjectDoesNotExist
1010from django .utils .text import slugify
11+ from opaque_keys import OpaqueKey
1112from opaque_keys .edx .keys import LearningContextKey , UsageKey
1213from opaque_keys .edx .locator import LibraryContainerLocator , LibraryLocatorV2
1314from openedx_learning .api import authoring as authoring_api
@@ -113,7 +114,7 @@ class PublishStatus:
113114 modified = "modified"
114115
115116
116- def meili_id_from_opaque_key (usage_key : UsageKey ) -> str :
117+ def meili_id_from_opaque_key (key : OpaqueKey ) -> str :
117118 """
118119 Meilisearch requires each document to have a primary key that's either an
119120 integer or a string composed of alphanumeric characters (a-z A-Z 0-9),
@@ -124,7 +125,7 @@ def meili_id_from_opaque_key(usage_key: UsageKey) -> str:
124125 we could use PublishableEntity's primary key / UUID instead.
125126 """
126127 # The slugified key _may_ not be unique so we append a hashed string to make it unique:
127- key_str = str (usage_key )
128+ key_str = str (key )
128129 key_bin = key_str .encode ()
129130
130131 suffix = blake2b (key_bin , digest_size = 4 , usedforsecurity = False ).hexdigest ()
@@ -140,12 +141,12 @@ def _meili_access_id_from_context_key(context_key: LearningContextKey) -> int:
140141 return access .id
141142
142143
143- def searchable_doc_for_usage_key ( usage_key : UsageKey ) -> dict :
144+ def searchable_doc_for_key ( key : OpaqueKey ) -> dict :
144145 """
145- Generates a base document identified by its usage key.
146+ Generates a base document identified by its opaque key.
146147 """
147148 return {
148- Fields .id : meili_id_from_opaque_key (usage_key ),
149+ Fields .id : meili_id_from_opaque_key (key ),
149150 }
150151
151152
@@ -244,7 +245,7 @@ class implementation returns only:
244245 return block_data
245246
246247
247- def _tags_for_content_object (object_id : UsageKey | LearningContextKey ) -> dict :
248+ def _tags_for_content_object (object_id : OpaqueKey ) -> dict :
248249 """
249250 Given an XBlock, course, library, etc., get the tag data for its index doc.
250251
@@ -406,7 +407,7 @@ def searchable_doc_for_library_block(xblock_metadata: lib_api.LibraryXBlockMetad
406407 block_published = None
407408 publish_status = PublishStatus .never
408409
409- doc = searchable_doc_for_usage_key (xblock_metadata .usage_key )
410+ doc = searchable_doc_for_key (xblock_metadata .usage_key )
410411 doc .update ({
411412 Fields .type : DocType .library_block ,
412413 Fields .breadcrumbs : [],
@@ -427,13 +428,13 @@ def searchable_doc_for_library_block(xblock_metadata: lib_api.LibraryXBlockMetad
427428 return doc
428429
429430
430- def searchable_doc_tags (usage_key : UsageKey ) -> dict :
431+ def searchable_doc_tags (key : OpaqueKey ) -> dict :
431432 """
432433 Generate a dictionary document suitable for ingestion into a search engine
433434 like Meilisearch or Elasticsearch, with the tags data for the given content object.
434435 """
435- doc = searchable_doc_for_usage_key ( usage_key )
436- doc .update (_tags_for_content_object (usage_key ))
436+ doc = searchable_doc_for_key ( key )
437+ doc .update (_tags_for_content_object (key ))
437438
438439 return doc
439440
@@ -443,7 +444,7 @@ def searchable_doc_collections(usage_key: UsageKey) -> dict:
443444 Generate a dictionary document suitable for ingestion into a search engine
444445 like Meilisearch or Elasticsearch, with the collections data for the given content object.
445446 """
446- doc = searchable_doc_for_usage_key (usage_key )
447+ doc = searchable_doc_for_key (usage_key )
447448 doc .update (_collections_for_content_object (usage_key ))
448449
449450 return doc
@@ -461,7 +462,7 @@ def searchable_doc_tags_for_collection(
461462 library_key ,
462463 collection_key ,
463464 )
464- doc = searchable_doc_for_usage_key (collection_usage_key )
465+ doc = searchable_doc_for_key (collection_usage_key )
465466 doc .update (_tags_for_content_object (collection_usage_key ))
466467
467468 return doc
@@ -473,7 +474,7 @@ def searchable_doc_for_course_block(block) -> dict:
473474 like Meilisearch or Elasticsearch, so that the given course block can be
474475 found using faceted search.
475476 """
476- doc = searchable_doc_for_usage_key (block .usage_key )
477+ doc = searchable_doc_for_key (block .usage_key )
477478 doc .update ({
478479 Fields .type : DocType .course_block ,
479480 })
@@ -503,7 +504,7 @@ def searchable_doc_for_collection(
503504 collection_key ,
504505 )
505506
506- doc = searchable_doc_for_usage_key (collection_usage_key )
507+ doc = searchable_doc_for_key (collection_usage_key )
507508
508509 try :
509510 collection = collection or lib_api .get_library_collection_from_usage_key (collection_usage_key )
0 commit comments