Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions cms/djangoapps/import_from_modulestore/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""
API for course to library import.
"""
from opaque_keys.edx.keys import LearningContextKey

from .models import Import as _Import
from .tasks import import_course_staged_content_to_library_task, save_legacy_content_to_staged_content_task
from .validators import validate_usage_keys_to_import


def create_import(source_key: LearningContextKey, user_id: int) -> _Import:
"""
Create a new import event to import a course to a library and save course to staged content.
"""
import_from_modulestore = _Import.objects.create(
source_key=source_key,
user_id=user_id,
)
save_legacy_content_to_staged_content_task.delay_on_commit(import_from_modulestore.uuid)
return import_from_modulestore


def import_course_staged_content_to_library(
usage_ids: list[str],
import_uuid: str,
target_learning_package_id: int,
user_id: int,
composition_level: str,
override: bool,
) -> None:
"""
Import staged content to a library from staged content.
"""
validate_usage_keys_to_import(usage_ids)
import_course_staged_content_to_library_task.apply_async(
kwargs={
'usage_keys_string': usage_ids,
'import_uuid': import_uuid,
'learning_package_id': target_learning_package_id,
'user_id': user_id,
'composition_level': composition_level,
'override': override,
},
)
5 changes: 5 additions & 0 deletions cms/djangoapps/import_from_modulestore/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""
Constants for import_from_modulestore app
"""

IMPORT_FROM_MODULESTORE_PURPOSE = "import_from_modulestore"
30 changes: 30 additions & 0 deletions cms/djangoapps/import_from_modulestore/data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""
This module contains the data models for the import_from_modulestore app.
"""
from collections import namedtuple
from enum import Enum

from django.db.models import TextChoices
from django.utils.translation import gettext_lazy as _

Expand All @@ -18,3 +21,30 @@ class ImportStatus(TextChoices):
IMPORTING_FAILED = 'importing_failed', _('Failed to import staged content')
IMPORTED = 'imported', _('Successfully imported content')
CANCELED = 'canceled', _('Canceled')


class CompositionLevel(Enum):
"""
Enumeration of composition levels for course content.
Defines the different levels of composition for course content,
including chapters, sequentials, verticals, and xblocks.
It also categorizes these levels into complicated and flat
levels for easier processing.
"""

CHAPTER = 'chapter'
SEQUENTIAL = 'sequential'
VERTICAL = 'vertical'
XBLOCK = 'xblock'
COMPLICATED_LEVELS = [CHAPTER, SEQUENTIAL, VERTICAL]
FLAT_LEVELS = [XBLOCK]

@classmethod
def values(cls):
"""
Returns all levels of composition levels.
"""
return [composition_level.value for composition_level in cls]


PublishableVersionWithMapping = namedtuple('PublishableVersionWithMapping', ['publishable_version', 'mapping'])
Loading
Loading