From 6725fa607a1c5507b7fc94675a0f46a13d01289d Mon Sep 17 00:00:00 2001 From: Taras Lytvynenko <69678257+Inferato@users.noreply.github.com> Date: Fri, 10 Nov 2023 01:04:49 +0200 Subject: [PATCH] fix: course mode added to the metadata --- .../course_home_api/course_metadata/serializers.py | 9 +++++++++ lms/djangoapps/course_home_api/course_metadata/views.py | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/lms/djangoapps/course_home_api/course_metadata/serializers.py b/lms/djangoapps/course_home_api/course_metadata/serializers.py index b140938f7e2d..2bafd7427a2e 100644 --- a/lms/djangoapps/course_home_api/course_metadata/serializers.py +++ b/lms/djangoapps/course_home_api/course_metadata/serializers.py @@ -29,6 +29,14 @@ def get_url(self, tab): return request.build_absolute_uri(tab.link_func(self.context.get('course'), reverse)) +class CourseModeSerrializer(serializers.Serializer): + """ + Serializer for the Course Mode + """ + slug = serializers.CharField() + name = serializers.CharField() + + class CourseHomeMetadataSerializer(VerifiedModeSerializer): """ Serializer for the Course Home Course Metadata @@ -48,3 +56,4 @@ class CourseHomeMetadataSerializer(VerifiedModeSerializer): username = serializers.CharField() user_timezone = serializers.CharField() can_view_certificate = serializers.BooleanField() + course_modes = CourseModeSerrializer(many=True) diff --git a/lms/djangoapps/course_home_api/course_metadata/views.py b/lms/djangoapps/course_home_api/course_metadata/views.py index ba789ea25458..e42c3ea3b71d 100644 --- a/lms/djangoapps/course_home_api/course_metadata/views.py +++ b/lms/djangoapps/course_home_api/course_metadata/views.py @@ -14,6 +14,7 @@ from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser from openedx.core.djangoapps.courseware_api.utils import get_celebrations_dict +from common.djangoapps.course_modes.models import CourseMode from common.djangoapps.student.models import CourseEnrollment from lms.djangoapps.course_api.api import course_detail from lms.djangoapps.course_goals.models import UserActivity @@ -117,6 +118,8 @@ def get(self, request, *args, **kwargs): # Record course goals user activity for (web) learning mfe course tabs UserActivity.record_user_activity(request.user, course_key) + course_modes = CourseMode.modes_for_course(course_key, include_expired=True, only_selectable=False) + data = { 'course_id': course.id, 'username': username, @@ -133,6 +136,7 @@ def get(self, request, *args, **kwargs): 'celebrations': celebrations, 'user_timezone': user_timezone, 'can_view_certificate': certificates_viewable_for_course(course), + 'course_modes': course_modes, } context = self.get_serializer_context() context['course'] = course