99from django .core .exceptions import ObjectDoesNotExist
1010from django .utils .text import slugify
1111from opaque_keys .edx .keys import LearningContextKey , UsageKey
12- from opaque_keys .edx .locator import LibraryContainerLocator , LibraryLocatorV2
12+ from opaque_keys .edx .locator import LibraryCollectionLocator , LibraryContainerLocator
1313from openedx_learning .api import authoring as authoring_api
1414from openedx_learning .api .authoring_models import Collection
1515from rest_framework .exceptions import NotFound
@@ -450,19 +450,14 @@ def searchable_doc_collections(usage_key: UsageKey) -> dict:
450450
451451
452452def searchable_doc_tags_for_collection (
453- library_key : LibraryLocatorV2 ,
454- collection_key : str ,
453+ collection_key : LibraryCollectionLocator
455454) -> dict :
456455 """
457456 Generate a dictionary document suitable for ingestion into a search engine
458457 like Meilisearch or Elasticsearch, with the tags data for the given library collection.
459458 """
460- collection_usage_key = lib_api .get_library_collection_usage_key (
461- library_key ,
462- collection_key ,
463- )
464- doc = searchable_doc_for_usage_key (collection_usage_key )
465- doc .update (_tags_for_content_object (collection_usage_key ))
459+ doc = searchable_doc_for_usage_key (collection_key )
460+ doc .update (_tags_for_content_object (collection_key ))
466461
467462 return doc
468463
@@ -484,8 +479,7 @@ def searchable_doc_for_course_block(block) -> dict:
484479
485480
486481def searchable_doc_for_collection (
487- library_key : LibraryLocatorV2 ,
488- collection_key : str ,
482+ collection_key : LibraryCollectionLocator ,
489483 * ,
490484 # Optionally provide the collection if we've already fetched one
491485 collection : Collection | None = None ,
@@ -498,21 +492,16 @@ def searchable_doc_for_collection(
498492 If no collection is found for the given library_key + collection_key, the returned document will contain only basic
499493 information derived from the collection usage key, and no Fields.type value will be included in the returned dict.
500494 """
501- collection_usage_key = lib_api .get_library_collection_usage_key (
502- library_key ,
503- collection_key ,
504- )
505-
506- doc = searchable_doc_for_usage_key (collection_usage_key )
495+ doc = searchable_doc_for_usage_key (collection_key )
507496
508497 try :
509- collection = collection or lib_api .get_library_collection_from_usage_key ( collection_usage_key )
498+ collection = collection or lib_api .get_library_collection_from_locator ( collection_key )
510499 except lib_api .ContentLibraryCollectionNotFound :
511500 # Collection not found, so we can only return the base doc
512501 pass
513502
514503 if collection :
515- assert collection .key == collection_key
504+ assert collection .key == collection_key . collection_id
516505
517506 draft_num_children = authoring_api .filter_publishable_entities (
518507 collection .entities ,
@@ -524,9 +513,9 @@ def searchable_doc_for_collection(
524513 ).count ()
525514
526515 doc .update ({
527- Fields .context_key : str (library_key ),
528- Fields .org : str (library_key .org ),
529- Fields .usage_key : str (collection_usage_key ),
516+ Fields .context_key : str (collection_key . library_key ),
517+ Fields .org : str (collection_key .org ),
518+ Fields .usage_key : str (collection_key ),
530519 Fields .block_id : collection .key ,
531520 Fields .type : DocType .collection ,
532521 Fields .display_name : collection .title ,
@@ -537,7 +526,7 @@ def searchable_doc_for_collection(
537526 Fields .published : {
538527 Fields .published_num_children : published_num_children ,
539528 },
540- Fields .access_id : _meili_access_id_from_context_key (library_key ),
529+ Fields .access_id : _meili_access_id_from_context_key (collection_key . library_key ),
541530 Fields .breadcrumbs : [{"display_name" : collection .learning_package .title }],
542531 })
543532
0 commit comments