Skip to content

Commit

Permalink
add duration and time_commitment to program API (#2422)
Browse files Browse the repository at this point in the history
  • Loading branch information
rachellougee authored Oct 22, 2024
1 parent 25a46f4 commit af58274
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
22 changes: 22 additions & 0 deletions courses/serializers/v2/programs.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class ProgramSerializer(serializers.ModelSerializer):
topics = serializers.SerializerMethodField()
certificate_type = serializers.SerializerMethodField()
required_prerequisites = serializers.SerializerMethodField()
duration = serializers.SerializerMethodField()
time_commitment = serializers.SerializerMethodField()

def get_courses(self, instance):
return [course[0].id for course in instance.courses if course[0].live]
Expand All @@ -45,6 +47,24 @@ def get_required_prerequisites(self, instance):
and instance.page.prerequisites != ""
)

def get_duration(self, instance):
"""
Get the length/duration field from the program page CMS.
"""
if hasattr(instance, "page") and hasattr(instance.page, "length"):
return instance.page.length

return None

def get_time_commitment(self, instance):
"""
Get the effort/time_commitment field from the program page CMS.
"""
if hasattr(instance, "page") and hasattr(instance.page, "effort"):
return instance.page.effort

return None

def get_req_tree(self, instance):
req_root = instance.get_requirements_root()

Expand Down Expand Up @@ -95,6 +115,8 @@ class Meta:
"enrollment_start",
"enrollment_end",
"required_prerequisites",
"duration",
"time_commitment",
]


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 @@ -105,5 +105,7 @@ def test_serialize_program(
"enrollment_start": program_with_empty_requirements.enrollment_start,
"enrollment_end": program_with_empty_requirements.enrollment_end,
"required_prerequisites": required_prerequisites,
"duration": program_with_empty_requirements.page.length,
"time_commitment": program_with_empty_requirements.page.effort,
},
)

0 comments on commit af58274

Please sign in to comment.