-
Notifications
You must be signed in to change notification settings - Fork 22
feat: add initial code to load a learning package #379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ormsbee
merged 3 commits into
openedx:main
from
WGU-Open-edX:dwong2708/lp_load_initial_lp_restore
Sep 18, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,25 @@ | ||
| """ | ||
| Backup Restore API | ||
| """ | ||
| from openedx_learning.apps.authoring.backup_restore.zipper import LearningPackageZipper | ||
| import zipfile | ||
|
|
||
| from openedx_learning.apps.authoring.backup_restore.zipper import LearningPackageUnzipper, LearningPackageZipper | ||
| from openedx_learning.apps.authoring.publishing.api import get_learning_package_by_key | ||
|
|
||
|
|
||
| def create_zip_file(lp_key: str, path: str) -> None: | ||
| """ | ||
| Creates a zip file with a toml file so far (WIP) | ||
| Creates a dump zip file for the given learning package key at the given path. | ||
|
|
||
| Can throw a NotFoundError at get_learning_package_by_key | ||
| """ | ||
| learning_package = get_learning_package_by_key(lp_key) | ||
| LearningPackageZipper(learning_package).create_zip(path) | ||
|
|
||
|
|
||
| def load_dump_zip_file(path: str) -> None: | ||
| """ | ||
| Loads a zip file derived from create_zip_file | ||
| """ | ||
| with zipfile.ZipFile(path, "r") as zipf: | ||
| LearningPackageUnzipper().load(zipf) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
openedx_learning/apps/authoring/backup_restore/management/commands/lp_load.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| """ | ||
| Django management commands to handle restore learning packages (WIP) | ||
| """ | ||
| import logging | ||
|
|
||
| from django.core.management import CommandError | ||
| from django.core.management.base import BaseCommand | ||
|
|
||
| from openedx_learning.apps.authoring.backup_restore.api import load_dump_zip_file | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class Command(BaseCommand): | ||
| """ | ||
| Django management command to load a learning package from a zip file. | ||
| """ | ||
| help = 'Load a learning package from a zip file.' | ||
|
|
||
| def add_arguments(self, parser): | ||
| parser.add_argument('file_name', type=str, help='The name of the input zip file to load.') | ||
|
|
||
| def handle(self, *args, **options): | ||
| file_name = options['file_name'] | ||
| if not file_name.lower().endswith(".zip"): | ||
| raise CommandError("Input file name must end with .zip") | ||
| try: | ||
| load_dump_zip_file(file_name) | ||
| message = f'{file_name} loaded successfully' | ||
| self.stdout.write(self.style.SUCCESS(message)) | ||
| except FileNotFoundError as exc: | ||
| message = f"Learning package file {file_name} not found" | ||
| raise CommandError(message) from exc | ||
| except Exception as e: | ||
| message = f"Failed to load '{file_name}': {e}" | ||
| logger.exception( | ||
| "Failed to load zip file %s ", | ||
| file_name, | ||
| ) | ||
| raise CommandError(message) from e |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: This is okay for now, but we may need to be more granular with this eventually, instead of putting it over the entire method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood