Skip to content
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

feat: add management command to archive bootcamps #4522

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
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}
15 changes: 15 additions & 0 deletions course_discovery/apps/course_metadata/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4707,3 +4707,18 @@ class RestrictedCourseRun(DraftModelMixin, TimeStampedModel):

def __str__(self):
return f"{self.course_run.key}: <{self.restriction_type}>"

class ArchiveBootcampsConfig(SingletonModel):
"""
Configuration for management command archive_bootcamps.
"""
bootcamp_uuids = models.TextField(
default=None,
null=True,
blank=False,
verbose_name=_('Bootcamp UUIDs'),
help_text=_('Comma-separated UUIDs of bootcamps to archive')
)

def __str__(self):
return _('Archive Bootcamps Config')
Loading