-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add management command to archive bootcamps
- Loading branch information
1 parent
1dde756
commit 92721e1
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
course_discovery/apps/course_metadata/management/commands/archive_bootcamps.py
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,47 @@ | ||
""" | ||
Management command for archiving bootcamps by course UUIDs. | ||
""" | ||
from django.core.management import BaseCommand, CommandError | ||
from django.utils.translation import gettext as _ | ||
|
||
from course_discovery.apps.course_metadata.models import Bootcamp, ArchiveBootcampsConfig | ||
|
||
|
||
class Command(BaseCommand): | ||
""" | ||
Management command to archive a list of bootcamps specified by course UUIDs. | ||
Example: | ||
./manage.py archive_bootcamps bootcamp0uuid bootcamp1uuid ... | ||
""" | ||
|
||
help = 'Archive a list of bootcamps specified by course UUIDs' | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
'bootcamps', nargs="*", help=_('UUIDs of bootcamps to archive') | ||
) | ||
parser.add_argument( | ||
'--args-from-database', action='store_true', | ||
help=_('Use arguments from the ArchiveBootcampsConfig model instead of the command line.') | ||
) | ||
|
||
def handle(self, *args, **options): | ||
if options['args_from_database']: | ||
config = ArchiveBootcampsConfig.get_solo() | ||
bootcamp_uuids = config.bootcamp_uuids | ||
if not bootcamp_uuids: | ||
raise CommandError(_('No bootcamp UUIDs found in the database configuration.')) | ||
bootcamp_uuids = bootcamp_uuids.split(", ") | ||
else: | ||
if not options['bootcamps']: | ||
raise CommandError(_('Missing required arguments')) | ||
bootcamp_uuids = options['bootcamps'] | ||
|
||
self.archive_bootcamps(bootcamp_uuids) | ||
|
||
def archive_bootcamps(self, bootcamp_uuids): | ||
|
||
|
||
def get_args_from_database(self): | ||
config = ArchiveBootcampsConfig.get_solo() | ||
return {"bootcamps": config.bootcamp_uuids} |
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