Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
958b903
feat: create import client
NiedielnitsevIvan Apr 17, 2025
4213966
feat: create celery tasks for import functionality
NiedielnitsevIvan Apr 17, 2025
c03dcd8
feat: add python APIs to create and process import
NiedielnitsevIvan Apr 17, 2025
a3ea142
style: fix pylint issues
NiedielnitsevIvan Apr 17, 2025
9acd085
test: add tests
NiedielnitsevIvan Apr 17, 2025
ff2903d
refactor: fix after rebase
NiedielnitsevIvan Apr 17, 2025
cbfe82d
refactor: fix after changed relations in the import models
NiedielnitsevIvan Apr 18, 2025
60de98a
test: update tests
NiedielnitsevIvan Apr 18, 2025
ee3f843
style: remove extra imports
NiedielnitsevIvan Apr 18, 2025
3e31032
refactor: signal logic moved to the seprate util
NiedielnitsevIvan Apr 22, 2025
359b2bc
refactor: rename purpose
NiedielnitsevIvan Apr 22, 2025
9abe4fc
refactor: rename APIs
NiedielnitsevIvan Apr 22, 2025
3aa550e
test: avoid using factories for content_library (#2635)
cmltaWt0 Apr 22, 2025
15fe9e5
refactor: refactor CompositionLevel enum
NiedielnitsevIvan Apr 22, 2025
5ff0620
fix: fix logic for not yet supported composition levels
NiedielnitsevIvan Apr 22, 2025
8cce09b
fix: comment tests for not yet supported composition levels
NiedielnitsevIvan Apr 22, 2025
9112822
refactor: fix issues after review
NiedielnitsevIvan Apr 23, 2025
5f6a1e5
feat: adding support for importing sections and subsections
NiedielnitsevIvan Apr 23, 2025
852a243
test: fix tests after refactoring
NiedielnitsevIvan Apr 23, 2025
9b96363
style: fix naming and add type hints
NiedielnitsevIvan Apr 23, 2025
227230b
chore: add cms/djangoapps/import_from_modulestore to mypy.ini
NiedielnitsevIvan Apr 23, 2025
2761d16
refactor: refactor Composition Levels
NiedielnitsevIvan Apr 23, 2025
a5595f2
refactor: improve static typization to fix mypy errors
Apr 23, 2025
51658aa
refactor: fix StagedContent import to prevent lint error
Apr 23, 2025
be631da
refactor: fix pylint error for error raising
Apr 23, 2025
9a881d8
Merge branch 'master' into NiedielnitsevIvan/feat/import-from-modules…
NiedielnitsevIvan Apr 23, 2025
c49cdae
refactor: improve Import client container mapps
NiedielnitsevIvan Apr 23, 2025
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
45 changes: 45 additions & 0 deletions cms/djangoapps/import_from_modulestore/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding so many type annotations! Please add cms/djangoapps/import_from_modulestore to mypy.ini so that they will be checked when mypy is executed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added, and type annotations have been improved a bit more.

API for course to library import.
"""
from typing import Sequence

from opaque_keys.edx.keys import LearningContextKey, UsageKey

from .helpers import cancel_incomplete_old_imports
from .models import Import as _Import
from .tasks import import_staged_content_to_library_task, save_legacy_content_to_staged_content_task
from .validators import validate_usage_keys_to_import


def stage_content_for_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)
cancel_incomplete_old_imports(import_from_modulestore)
save_legacy_content_to_staged_content_task.delay_on_commit(import_from_modulestore.uuid)
return import_from_modulestore


def import_staged_content_to_library(
usage_ids: Sequence[str | UsageKey],
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_staged_content_to_library_task.apply_async(
kwargs={
'usage_key_strings': 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_STAGING_PURPOSE = "import_from_modulestore"
34 changes: 34 additions & 0 deletions cms/djangoapps/import_from_modulestore/data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
"""
This module contains the data models for the import_from_modulestore app.
"""
from collections import namedtuple
from enum import Enum
from openedx.core.djangoapps.content_libraries import api as content_libraries_api

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

Expand All @@ -18,3 +22,33 @@ 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 = content_libraries_api.ContainerType.Section
SEQUENTIAL = content_libraries_api.ContainerType.Subsection
VERTICAL = content_libraries_api.ContainerType.Unit
COMPONENT = 'component'
OLX_COMPLEX_LEVELS = [
VERTICAL.olx_tag,
SEQUENTIAL.olx_tag,
CHAPTER.olx_tag,
]

@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