-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add import_projectbackup management command
This is useful for importing huge backups not suitable for file upload.
- Loading branch information
Showing
5 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,36 @@ | ||
# Copyright © Michal Čihař <[email protected]> | ||
# | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
from __future__ import annotations | ||
|
||
from weblate.auth.models import User | ||
from weblate.trans.backups import ProjectBackup | ||
from weblate.utils.management.base import BaseCommand | ||
|
||
|
||
class Command(BaseCommand): | ||
"""Command for importing project backup into Weblate.""" | ||
|
||
help = "imports project backup" | ||
|
||
def add_arguments(self, parser) -> None: | ||
super().add_arguments(parser) | ||
parser.add_argument("project_name", help="Project name") | ||
parser.add_argument("project_slug", help="Project slug") | ||
parser.add_argument("username", help="Username doing import") | ||
parser.add_argument("filename", help="Path to project backup") | ||
|
||
def handle( | ||
self, | ||
project_name: str, | ||
project_slug: str, | ||
username: str, | ||
filename: str, | ||
**options, | ||
) -> None: | ||
user = User.objects.get(username=username) | ||
restore = ProjectBackup(filename) | ||
|
||
restore.validate() | ||
|
||
restore.restore(project_name=project_name, project_slug=project_slug, user=user) |
This file contains 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