Skip to content

Commit

Permalink
feat: add bootcamps url restructuring method to command
Browse files Browse the repository at this point in the history
  • Loading branch information
AfaqShuaib09 committed Sep 4, 2023
1 parent 2f2307f commit 916e408
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 3 deletions.
2 changes: 1 addition & 1 deletion course_discovery/apps/course_metadata/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
REFRESH_COURSE_SKILLS_URL_NAME = 'refresh_course_skills'
REFRESH_PROGRAM_SKILLS_URL_NAME = 'refresh_program_skills'
COURSE_UUID_REGEX = r'[0-9a-f-]+'
SUBDIRECTORY_SLUG_FORMAT_REGEX = r'learn\/[a-zA-Z0-9-_]+\/[a-zA-Z0-9-_]+$|executive-education\/[a-zA-Z0-9-_]+$'
SUBDIRECTORY_SLUG_FORMAT_REGEX = r"learn\/[a-zA-Z0-9-_]+\/[a-zA-Z0-9-_]+$|executive-education\/[a-zA-Z0-9-_]+$|learn\/[a-zA-Z0-9-_]+\/[a-zA-Z0-9-_]+$"
SLUG_FORMAT_REGEX = r'[a-zA-Z0-9-_]+$'

DEFAULT_SLUG_FORMAT_ERROR_MSG = 'Enter a valid “slug” consisting of letters, numbers, underscores or hyphens.'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
class Command(BaseCommand):
help = """
It will update course url slugs to the format 'learn/<primary_subject>/<organization_name>-<course_title>' for
open courses and 'executive-education/<organization_name>-<course_title>' for executive education courses
open courses, 'executive-education/<organization_name>-<course_title>' for executive education courses, and
'boot-camps/<primary-subject>/<organization_name>-<course_title>' for bootcamps
"""

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -55,7 +56,7 @@ def add_arguments(self, parser):
'--course_type',
help='Course Type to update slug',
type=str,
choices=[CourseType.EXECUTIVE_EDUCATION_2U, 'open-course'],
choices=[CourseType.BOOTCAMP_2U, CourseType.EXECUTIVE_EDUCATION_2U, 'open-course'],
default='open-course',
)
parser.add_argument(
Expand Down Expand Up @@ -186,6 +187,8 @@ def _get_courses(self):
courses = Course.everything.filter(product_source__slug=self.product_source, draft=True)
if self.course_type == CourseType.EXECUTIVE_EDUCATION_2U:
return courses.filter(type__slug=CourseType.EXECUTIVE_EDUCATION_2U)
elif self.course_type == CourseType.BOOTCAMP_2U:
return courses.filter(type__slug=CourseType.BOOTCAMP_2U)
# Return Open Courses only
return courses.exclude(type__slug__in=[CourseType.EXECUTIVE_EDUCATION_2U, CourseType.BOOTCAMP_2U])

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.20 on 2023-09-01 13:26

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('course_metadata', '0331_auto_20230810_0748'),
]

operations = [
migrations.AlterField(
model_name='migratecourseslugconfiguration',
name='course_type',
field=models.CharField(choices=[('open-course', 'Open Courses'), ('executive-education-2u', '2U Executive Education Courses'), ('bootcamp-2u', 'Bootcamps')], default='open-course', max_length=255),
),
]
1 change: 1 addition & 0 deletions course_discovery/apps/course_metadata/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4219,6 +4219,7 @@ class MigrateCourseSlugConfiguration(ConfigurationModel):
COURSE_TYPE_CHOICES = (
(OPEN_COURSE, _('Open Courses')),
(CourseType.EXECUTIVE_EDUCATION_2U, _('2U Executive Education Courses')),
(CourseType.BOOTCAMP_2U, _('Bootcamps'))
)
# Timeout set to 0 so that the model does not read from cached config in case the config entry is deleted.
cache_timeout = 0
Expand Down
19 changes: 19 additions & 0 deletions course_discovery/apps/course_metadata/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,22 @@ def create_slug_for_exec_ed():
slug = f"executive-education/{organization_slug}-{course_slug}"
return slug, error

def create_slug_for_bootcamps():
course_slug = slugify(course.title)
course_subjects = course.subjects.all()
if not course_subjects:
error = f"Bootcamp with uuid {course.uuid} and title {course.title} does not have any subject"
logger.info(error)
return None, error
primary_subject_slug = course_subjects[0].slug

slug = f'boot-camps/{primary_subject_slug}/{organization_slug}-{course_slug}'
if is_existing_slug(slug, course):
logger.info(f"Slug '{slug}' already exists in DB, recreating slug by adding a number in course_title")
course_slug = f"{slugify(course.title)}-{get_existing_slug_count(slug) + 1}"
slug = f"boot-camps/{primary_subject_slug}/{organization_slug}-{course_slug}"
return slug, error

def create_slug_for_ocm():
course_subjects = course.subjects.all()
if not course_subjects:
Expand All @@ -1042,6 +1058,9 @@ def create_slug_for_ocm():
slug = f"learn/{primary_subject_slug}/{organization_slug}-{course_slug}"
return slug, None

if course.type.slug == CourseType.BOOTCAMP_2U:
return create_slug_for_bootcamps()

if course.type.slug == CourseType.EXECUTIVE_EDUCATION_2U:
return create_slug_for_exec_ed()

Expand Down

0 comments on commit 916e408

Please sign in to comment.