Skip to content

Commit

Permalink
feat: add management command to archive bootcamps
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali-D-Akbar committed Dec 23, 2024
1 parent 1dde756 commit 92721e1
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
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')

0 comments on commit 92721e1

Please sign in to comment.