diff --git a/cms/factories.py b/cms/factories.py index 4eb7342dd..c0077533b 100644 --- a/cms/factories.py +++ b/cms/factories.py @@ -70,6 +70,8 @@ class CoursePageFactory(wagtail_factories.PageFactory): ) min_weekly_hours = fuzzy.FuzzyInteger(1, 40) max_weekly_hours = fuzzy.FuzzyInteger(1, 40) + min_weeks = fuzzy.FuzzyInteger(1, 300) + max_weeks = fuzzy.FuzzyInteger(1, 300) class Meta: model = CoursePage @@ -91,6 +93,8 @@ class ProgramPageFactory(wagtail_factories.PageFactory): ) min_weekly_hours = fuzzy.FuzzyInteger(1, 40) max_weekly_hours = fuzzy.FuzzyInteger(1, 40) + min_weeks = fuzzy.FuzzyInteger(1, 300) + max_weeks = fuzzy.FuzzyInteger(1, 300) class Meta: model = ProgramPage diff --git a/cms/migrations/0040_coursepage_max_weeks_coursepage_min_weeks_and_more.py b/cms/migrations/0040_coursepage_max_weeks_coursepage_min_weeks_and_more.py new file mode 100644 index 000000000..eeee1e1c9 --- /dev/null +++ b/cms/migrations/0040_coursepage_max_weeks_coursepage_min_weeks_and_more.py @@ -0,0 +1,48 @@ +# Generated by Django 4.2.16 on 2024-11-25 16:19 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("cms", "0039_coursepage_max_weekly_hours_and_more"), + ] + + operations = [ + migrations.AddField( + model_name="coursepage", + name="max_weeks", + field=models.SmallIntegerField( + blank=True, + help_text="The maximum number of weeks required to complete the course/program.", + null=True, + ), + ), + migrations.AddField( + model_name="coursepage", + name="min_weeks", + field=models.SmallIntegerField( + blank=True, + help_text="The minimum number of weeks required to complete the course/program.", + null=True, + ), + ), + migrations.AddField( + model_name="programpage", + name="max_weeks", + field=models.SmallIntegerField( + blank=True, + help_text="The maximum number of weeks required to complete the course/program.", + null=True, + ), + ), + migrations.AddField( + model_name="programpage", + name="min_weeks", + field=models.SmallIntegerField( + blank=True, + help_text="The minimum number of weeks required to complete the course/program.", + null=True, + ), + ), + ] diff --git a/cms/models.py b/cms/models.py index 7244d1c52..fe291227f 100644 --- a/cms/models.py +++ b/cms/models.py @@ -984,6 +984,18 @@ class Meta: help_text="The maximum number of hours per week required to complete the course.", ) + min_weeks = models.SmallIntegerField( + null=True, + blank=True, + help_text="The minimum number of weeks required to complete the course/program.", + ) + + max_weeks = models.SmallIntegerField( + null=True, + blank=True, + help_text="The maximum number of weeks required to complete the course/program.", + ) + effort = models.CharField( # noqa: DJ001 max_length=100, null=True, @@ -1080,6 +1092,8 @@ def is_program_page(self): FieldPanel("effort"), FieldPanel("min_weekly_hours"), FieldPanel("max_weekly_hours"), + FieldPanel("min_weeks"), + FieldPanel("max_weeks"), FieldPanel("price"), FieldPanel("prerequisites"), FieldPanel("faq_url"), diff --git a/courses/serializers/v2/courses.py b/courses/serializers/v2/courses.py index b07f7722b..42a6b2a2c 100644 --- a/courses/serializers/v2/courses.py +++ b/courses/serializers/v2/courses.py @@ -36,6 +36,8 @@ class CourseSerializer(BaseCourseSerializer): availability = serializers.SerializerMethodField() required_prerequisites = serializers.SerializerMethodField() duration = serializers.SerializerMethodField() + min_weeks = serializers.SerializerMethodField() + max_weeks = serializers.SerializerMethodField() time_commitment = serializers.SerializerMethodField() min_weekly_hours = serializers.SerializerMethodField() max_weekly_hours = serializers.SerializerMethodField() @@ -124,6 +126,24 @@ def get_availability(self, instance): return "anytime" return "dated" + def get_min_weeks(self, instance): + """ + Get the min weeks of the course from the CMS page. + """ + if hasattr(instance, "page") and hasattr(instance.page, "min_weeks"): + return instance.page.min_weeks + + return None + + def get_max_weeks(self, instance): + """ + Get the max weeks of the course from the CMS page. + """ + if hasattr(instance, "page") and hasattr(instance.page, "max_weeks"): + return instance.page.max_weeks + + return None + class Meta: model = models.Course fields = [ @@ -138,6 +158,8 @@ class Meta: "certificate_type", "required_prerequisites", "duration", + "min_weeks", + "max_weeks", "time_commitment", "availability", "min_weekly_hours", diff --git a/courses/serializers/v2/courses_test.py b/courses/serializers/v2/courses_test.py index aff25aae6..567ccc673 100644 --- a/courses/serializers/v2/courses_test.py +++ b/courses/serializers/v2/courses_test.py @@ -72,6 +72,8 @@ def test_serialize_course( "topics": [{"name": topic.name} for topic in topics], "required_prerequisites": True, "duration": course.page.length, + "max_weeks": course.page.max_weeks, + "min_weeks": course.page.min_weeks, "time_commitment": course.page.effort, "programs": BaseProgramSerializer(course.programs, many=True).data if all_runs @@ -113,6 +115,8 @@ def test_serialize_course_required_prerequisites( "availability": "anytime", "required_prerequisites": expected_required_prerequisites, "duration": course.page.length, + "max_weeks": course.page.max_weeks, + "min_weeks": course.page.min_weeks, "time_commitment": course.page.effort, "programs": None, }, diff --git a/courses/serializers/v2/programs.py b/courses/serializers/v2/programs.py index 66ae11b72..a880ebd64 100644 --- a/courses/serializers/v2/programs.py +++ b/courses/serializers/v2/programs.py @@ -26,6 +26,8 @@ class ProgramSerializer(serializers.ModelSerializer): certificate_type = serializers.SerializerMethodField() required_prerequisites = serializers.SerializerMethodField() duration = serializers.SerializerMethodField() + min_weeks = serializers.SerializerMethodField() + max_weeks = serializers.SerializerMethodField() time_commitment = serializers.SerializerMethodField() min_weekly_hours = serializers.SerializerMethodField() max_weekly_hours = serializers.SerializerMethodField() @@ -114,6 +116,24 @@ def get_max_weekly_hours(self, instance): return None + def get_min_weeks(self, instance): + """ + Get the min weeks of the program from the CMS page. + """ + if hasattr(instance, "page") and hasattr(instance.page, "min_weeks"): + return instance.page.min_weeks + + return None + + def get_max_weeks(self, instance): + """ + Get the max weeks of the program from the CMS page. + """ + if hasattr(instance, "page") and hasattr(instance.page, "max_weeks"): + return instance.page.max_weeks + + return None + class Meta: model = Program fields = [ @@ -136,6 +156,8 @@ class Meta: "enrollment_end", "required_prerequisites", "duration", + "min_weeks", + "max_weeks", "time_commitment", "min_weekly_hours", "max_weekly_hours", diff --git a/courses/serializers/v2/programs_test.py b/courses/serializers/v2/programs_test.py index 181a83d74..c75c85a5d 100644 --- a/courses/serializers/v2/programs_test.py +++ b/courses/serializers/v2/programs_test.py @@ -106,6 +106,8 @@ def test_serialize_program( "enrollment_end": program_with_empty_requirements.enrollment_end, "required_prerequisites": required_prerequisites, "duration": program_with_empty_requirements.page.length, + "max_weeks": program_with_empty_requirements.page.max_weeks, + "min_weeks": program_with_empty_requirements.page.min_weeks, "time_commitment": program_with_empty_requirements.page.effort, "max_weekly_hours": program_with_empty_requirements.page.max_weekly_hours, "min_weekly_hours": program_with_empty_requirements.page.min_weekly_hours,