Skip to content

Commit

Permalink
5999 provide standardized time commitment values in the mitx online a…
Browse files Browse the repository at this point in the history
…pi (#2451)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
cp-at-mit and pre-commit-ci[bot] authored Nov 19, 2024
1 parent e01d4ac commit b975a76
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cms/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions cms/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
48 changes: 48 additions & 0 deletions cms/migrations/0039_coursepage_max_weekly_hours_and_more.py
Original file line number Diff line number Diff line change
@@ -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,
),
),
]
14 changes: 14 additions & 0 deletions cms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"),
Expand Down
22 changes: 22 additions & 0 deletions courses/serializers/v2/courses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -120,6 +140,8 @@ class Meta:
"duration",
"time_commitment",
"availability",
"min_weekly_hours",
"max_weekly_hours",
]


Expand Down
4 changes: 4 additions & 0 deletions courses/serializers/v2/courses_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit b975a76

Please sign in to comment.