diff --git a/cms/api.py b/cms/api.py index 40f49cb0eb..5e906008ed 100644 --- a/cms/api.py +++ b/cms/api.py @@ -287,6 +287,8 @@ def create_default_courseware_page( "live": live, "length": "No Data", "slug": slugify(courseware.readable_id), + "max_weekly_hours": "Empty", + "min_weekly_hours": "Empty", } try: diff --git a/cms/factories.py b/cms/factories.py index 26c903aed9..4eb7342dd4 100644 --- a/cms/factories.py +++ b/cms/factories.py @@ -68,6 +68,8 @@ class CoursePageFactory(wagtail_factories.PageFactory): certificate_page = factory.RelatedFactory( "cms.factories.CertificatePageFactory", "parent" ) + min_weekly_hours = fuzzy.FuzzyInteger(1, 40) + max_weekly_hours = fuzzy.FuzzyInteger(1, 40) class Meta: model = CoursePage @@ -87,6 +89,8 @@ class ProgramPageFactory(wagtail_factories.PageFactory): certificate_page = factory.RelatedFactory( "cms.factories.CertificatePageFactory", "parent" ) + min_weekly_hours = fuzzy.FuzzyInteger(1, 40) + max_weekly_hours = fuzzy.FuzzyInteger(1, 40) class Meta: model = ProgramPage diff --git a/cms/migrations/0039_coursepage_max_weekly_hours_and_more.py b/cms/migrations/0039_coursepage_max_weekly_hours_and_more.py new file mode 100644 index 0000000000..f0ee3f2131 --- /dev/null +++ b/cms/migrations/0039_coursepage_max_weekly_hours_and_more.py @@ -0,0 +1,48 @@ +# Generated by Django 4.2.16 on 2024-11-18 17:08 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("cms", "0038_alter_instructorpagelink_linked_instructor_page"), + ] + + operations = [ + migrations.AddField( + model_name="coursepage", + name="max_weekly_hours", + field=models.CharField( + default="", + help_text="The maximum number of hours per week required to complete the course.", + max_length=5, + ), + ), + migrations.AddField( + model_name="coursepage", + name="min_weekly_hours", + field=models.CharField( + default="", + help_text="The minimum number of hours per week required to complete the course.", + max_length=5, + ), + ), + migrations.AddField( + model_name="programpage", + name="max_weekly_hours", + field=models.CharField( + default="", + help_text="The maximum number of hours per week required to complete the course.", + max_length=5, + ), + ), + migrations.AddField( + model_name="programpage", + name="min_weekly_hours", + field=models.CharField( + default="", + help_text="The minimum number of hours per week required to complete the course.", + max_length=5, + ), + ), + ] diff --git a/cms/models.py b/cms/models.py index 339114634a..7244d1c525 100644 --- a/cms/models.py +++ b/cms/models.py @@ -972,6 +972,18 @@ class Meta: help_text="A short description indicating how long it takes to complete (e.g. '4 weeks').", ) + min_weekly_hours = models.CharField( + max_length=5, + default="", + help_text="The minimum number of hours per week required to complete the course.", + ) + + max_weekly_hours = models.CharField( + max_length=5, + default="", + help_text="The maximum number of hours per week required to complete the course.", + ) + effort = models.CharField( # noqa: DJ001 max_length=100, null=True, @@ -1066,6 +1078,8 @@ def is_program_page(self): FieldPanel("description"), FieldPanel("length"), FieldPanel("effort"), + FieldPanel("min_weekly_hours"), + FieldPanel("max_weekly_hours"), FieldPanel("price"), FieldPanel("prerequisites"), FieldPanel("faq_url"), diff --git a/courses/serializers/v2/courses.py b/courses/serializers/v2/courses.py index 0eac4d0cb0..b07f7722b1 100644 --- a/courses/serializers/v2/courses.py +++ b/courses/serializers/v2/courses.py @@ -37,6 +37,8 @@ class CourseSerializer(BaseCourseSerializer): required_prerequisites = serializers.SerializerMethodField() duration = serializers.SerializerMethodField() time_commitment = serializers.SerializerMethodField() + min_weekly_hours = serializers.SerializerMethodField() + max_weekly_hours = serializers.SerializerMethodField() def get_required_prerequisites(self, instance): """ @@ -68,6 +70,24 @@ def get_time_commitment(self, instance): return None + def get_min_weekly_hours(self, instance): + """ + Get the min weekly hours of the course from the course page CMS. + """ + if hasattr(instance, "page") and hasattr(instance.page, "min_weekly_hours"): + return instance.page.min_weekly_hours + + return None + + def get_max_weekly_hours(self, instance): + """ + Get the max weekly hours of the course from the course page CMS. + """ + if hasattr(instance, "page") and hasattr(instance.page, "max_weekly_hours"): + return instance.page.max_weekly_hours + + return None + def get_next_run_id(self, instance): """Get next run id""" run = instance.first_unexpired_run @@ -120,6 +140,8 @@ class Meta: "duration", "time_commitment", "availability", + "min_weekly_hours", + "max_weekly_hours", ] diff --git a/courses/serializers/v2/courses_test.py b/courses/serializers/v2/courses_test.py index eed438c998..aff25aae6f 100644 --- a/courses/serializers/v2/courses_test.py +++ b/courses/serializers/v2/courses_test.py @@ -63,6 +63,8 @@ def test_serialize_course( CourseRunSerializer(courseRun2).data, ], "next_run_id": course.first_unexpired_run.id, + "max_weekly_hours": course.page.max_weekly_hours, + "min_weekly_hours": course.page.min_weekly_hours, "departments": [{"name": department}], "page": CoursePageSerializer(course.page).data, "certificate_type": certificate_type, @@ -102,6 +104,8 @@ def test_serialize_course_required_prerequisites( "id": course.id, "courseruns": [], "next_run_id": None, + "max_weekly_hours": course.page.max_weekly_hours, + "min_weekly_hours": course.page.min_weekly_hours, "departments": [], "page": CoursePageSerializer(course.page).data, "certificate_type": "Certificate of Completion",