Skip to content

Commit 3f67f3c

Browse files
feat: Import from modulestore APIs (#36540)
This PR is addressed at adding the functionality to import modulestore-based content to the learning-core based learning package. Partof: openedx/frontend-app-authoring#1681
1 parent 5445314 commit 3f67f3c

15 files changed

Lines changed: 1424 additions & 12 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""
2+
API for course to library import.
3+
"""
4+
from typing import Sequence
5+
6+
from opaque_keys.edx.keys import LearningContextKey, UsageKey
7+
8+
from .helpers import cancel_incomplete_old_imports
9+
from .models import Import as _Import
10+
from .tasks import import_staged_content_to_library_task, save_legacy_content_to_staged_content_task
11+
from .validators import validate_usage_keys_to_import
12+
13+
14+
def stage_content_for_import(source_key: LearningContextKey, user_id: int) -> _Import:
15+
"""
16+
Create a new import event to import a course to a library and save course to staged content.
17+
"""
18+
import_from_modulestore = _Import.objects.create(source_key=source_key, user_id=user_id)
19+
cancel_incomplete_old_imports(import_from_modulestore)
20+
save_legacy_content_to_staged_content_task.delay_on_commit(import_from_modulestore.uuid)
21+
return import_from_modulestore
22+
23+
24+
def import_staged_content_to_library(
25+
usage_ids: Sequence[str | UsageKey],
26+
import_uuid: str,
27+
target_learning_package_id: int,
28+
user_id: int,
29+
composition_level: str,
30+
override: bool,
31+
) -> None:
32+
"""
33+
Import staged content to a library from staged content.
34+
"""
35+
validate_usage_keys_to_import(usage_ids)
36+
import_staged_content_to_library_task.apply_async(
37+
kwargs={
38+
'usage_key_strings': usage_ids,
39+
'import_uuid': import_uuid,
40+
'learning_package_id': target_learning_package_id,
41+
'user_id': user_id,
42+
'composition_level': composition_level,
43+
'override': override,
44+
},
45+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""
2+
Constants for import_from_modulestore app
3+
"""
4+
5+
IMPORT_FROM_MODULESTORE_STAGING_PURPOSE = "import_from_modulestore"

cms/djangoapps/import_from_modulestore/data.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
"""
22
This module contains the data models for the import_from_modulestore app.
33
"""
4+
from collections import namedtuple
5+
from enum import Enum
6+
from openedx.core.djangoapps.content_libraries import api as content_libraries_api
7+
48
from django.db.models import TextChoices
59
from django.utils.translation import gettext_lazy as _
610

@@ -18,3 +22,33 @@ class ImportStatus(TextChoices):
1822
IMPORTING_FAILED = 'importing_failed', _('Failed to import staged content')
1923
IMPORTED = 'imported', _('Successfully imported content')
2024
CANCELED = 'canceled', _('Canceled')
25+
26+
27+
class CompositionLevel(Enum):
28+
"""
29+
Enumeration of composition levels for course content.
30+
Defines the different levels of composition for course content,
31+
including chapters, sequentials, verticals, and xblocks.
32+
It also categorizes these levels into complicated and flat
33+
levels for easier processing.
34+
"""
35+
36+
CHAPTER = content_libraries_api.ContainerType.Section
37+
SEQUENTIAL = content_libraries_api.ContainerType.Subsection
38+
VERTICAL = content_libraries_api.ContainerType.Unit
39+
COMPONENT = 'component'
40+
OLX_COMPLEX_LEVELS = [
41+
VERTICAL.olx_tag,
42+
SEQUENTIAL.olx_tag,
43+
CHAPTER.olx_tag,
44+
]
45+
46+
@classmethod
47+
def values(cls):
48+
"""
49+
Returns all levels of composition levels.
50+
"""
51+
return [composition_level.value for composition_level in cls]
52+
53+
54+
PublishableVersionWithMapping = namedtuple('PublishableVersionWithMapping', ['publishable_version', 'mapping'])

0 commit comments

Comments
 (0)