Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add time_commitment and durations to the courses api #2334

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
},
)
Loading