refactor: update to use Learning Core's new public API

This also bumps our openedx-learning dependency to 0.10.0 (the first
version with the new openedx_learning.api package).
This commit is contained in:
David Ormsbee
2024-05-16 13:08:02 -04:00
parent f820961de5
commit be03938377
13 changed files with 59 additions and 56 deletions

View File

@@ -15,12 +15,10 @@ import threading
from django.urls import reverse
from django.utils.translation import gettext as _
from openedx_learning.core.components import api as components_api
from openedx_learning.core.components.models import Component
from openedx_learning.core.publishing import api as publishing_api
from openedx_learning.api import authoring as authoring_api
from openedx_learning.api.authoring_models import Component
from opaque_keys.edx.keys import UsageKeyV2
from opaque_keys.edx.locator import BundleDefinitionLocator, LibraryUsageLocatorV2
from rest_framework.exceptions import NotFound
from xblock.core import XBlock
from xblock.exceptions import NoSuchViewError
@@ -28,13 +26,10 @@ from xblock.plugin import PluginMissingError
from openedx.core.djangoapps.xblock.apps import get_xblock_app_config
from openedx.core.djangoapps.xblock.learning_context.manager import get_learning_context_impl
from openedx.core.djangoapps.xblock.runtime.learning_core_runtime import (
LearningCoreFieldData,
LearningCoreXBlockRuntime,
)
from openedx.core.djangoapps.xblock.runtime.runtime import XBlockRuntimeSystem as _XBlockRuntimeSystem
from .utils import get_secure_token_for_xblock_handler, get_xblock_id_for_anonymous_user
@@ -192,10 +187,10 @@ def get_component_from_usage_key(usage_key: UsageKeyV2) -> Component:
This is a lower-level function that will return a Component even if there is
no current draft version of that Component (because it's been soft-deleted).
"""
learning_package = publishing_api.get_learning_package_by_key(
learning_package = authoring_api.get_learning_package_by_key(
str(usage_key.context_key)
)
return components_api.get_component_by_key(
return authoring_api.get_component_by_key(
learning_package.id,
namespace='xblock.v1',
type_name=usage_key.block_type,

View File

@@ -10,9 +10,7 @@ from datetime import datetime, timezone
from django.core.exceptions import ObjectDoesNotExist
from django.db.transaction import atomic
from openedx_learning.core.components import api as components_api
from openedx_learning.core.contents import api as contents_api
from openedx_learning.core.publishing import api as publishing_api
from openedx_learning.api import authoring as authoring_api
from lxml import etree
@@ -239,16 +237,16 @@ class LearningCoreXBlockRuntime(XBlockRuntime):
usage_key = block.scope_ids.usage_id
with atomic():
component = self._get_component_from_usage_key(usage_key)
block_media_type = contents_api.get_or_create_media_type(
block_media_type = authoring_api.get_or_create_media_type(
f"application/vnd.openedx.xblock.v1.{usage_key.block_type}+xml"
)
content = contents_api.get_or_create_text_content(
content = authoring_api.get_or_create_text_content(
component.learning_package_id,
block_media_type.id,
text=serialized.olx_str,
created=now,
)
components_api.create_next_version(
authoring_api.create_next_version(
component.pk,
title=block.display_name,
content_to_replace={
@@ -267,9 +265,9 @@ class LearningCoreXBlockRuntime(XBlockRuntime):
TODO: This is the third place where we're implementing this. Figure out
where the definitive place should be and have everything else call that.
"""
learning_package = publishing_api.get_learning_package_by_key(str(usage_key.lib_key))
learning_package = authoring_api.get_learning_package_by_key(str(usage_key.lib_key))
try:
component = components_api.get_component_by_key(
component = authoring_api.get_component_by_key(
learning_package.id,
namespace='xblock.v1',
type_name=usage_key.block_type,