Skip to content

Commit

Permalink
Add time_commitment and durations to the courses api (#2334)
Browse files Browse the repository at this point in the history
  • Loading branch information
annagav authored Aug 14, 2024
1 parent aa4afcb commit e5eb236
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
22 changes: 22 additions & 0 deletions courses/serializers/v2/courses.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class CourseSerializer(BaseCourseSerializer):
topics = serializers.SerializerMethodField()
certificate_type = serializers.SerializerMethodField()
required_prerequisites = serializers.SerializerMethodField()
duration = serializers.SerializerMethodField()
time_commitment = serializers.SerializerMethodField()

def get_required_prerequisites(self, instance):
"""
Expand All @@ -46,6 +48,24 @@ def get_required_prerequisites(self, instance):
and instance.page.prerequisites != ""
)

def get_duration(self, instance):
"""
Get the duration of the course from the course 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 time commitment of the course from the course page CMS.
"""
if hasattr(instance, "page") and hasattr(instance.page, "effort"):
return instance.page.effort

return None

def get_next_run_id(self, instance):
"""Get next run id"""
run = instance.first_unexpired_run
Expand Down Expand Up @@ -88,6 +108,8 @@ class Meta:
"topics",
"certificate_type",
"required_prerequisites",
"duration",
"time_commitment",
]


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 @@ -68,6 +68,8 @@ def test_serialize_course(
"certificate_type": certificate_type,
"topics": [{"name": topic.name} for topic in topics],
"required_prerequisites": True,
"duration": course.page.length,
"time_commitment": course.page.effort,
"programs": BaseProgramSerializer(course.programs, many=True).data
if all_runs
else None,
Expand Down Expand Up @@ -104,6 +106,8 @@ def test_serialize_course_required_prerequisites(
"certificate_type": "Certificate of Completion",
"topics": [],
"required_prerequisites": expected_required_prerequisites,
"duration": course.page.length,
"time_commitment": course.page.effort,
"programs": None,
},
)

0 comments on commit e5eb236

Please sign in to comment.