Skip to content

Commit

Permalink
Add min/max weeks for course and programs api (#2478)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
annagav and pre-commit-ci[bot] authored Dec 2, 2024
1 parent 94c76dd commit 7460bfc
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cms/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
),
),
]
14 changes: 14 additions & 0 deletions cms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"),
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 @@ -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()
Expand Down Expand Up @@ -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 = [
Expand All @@ -138,6 +158,8 @@ class Meta:
"certificate_type",
"required_prerequisites",
"duration",
"min_weeks",
"max_weeks",
"time_commitment",
"availability",
"min_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 @@ -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
Expand Down Expand Up @@ -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,
},
Expand Down
22 changes: 22 additions & 0 deletions courses/serializers/v2/programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 = [
Expand All @@ -136,6 +156,8 @@ class Meta:
"enrollment_end",
"required_prerequisites",
"duration",
"min_weeks",
"max_weeks",
"time_commitment",
"min_weekly_hours",
"max_weekly_hours",
Expand Down
2 changes: 2 additions & 0 deletions courses/serializers/v2/programs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7460bfc

Please sign in to comment.