From 962e45196f869d0dfab7ad469093fe366a1e5ad3 Mon Sep 17 00:00:00 2001 From: Muhammad Bilal Tahir <106396899+bilaltahir21@users.noreply.github.com> Date: Wed, 19 Jul 2023 18:46:37 +0500 Subject: [PATCH] feat: hook for course hasStarted attribute --- lms/djangoapps/learner_home/serializers.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lms/djangoapps/learner_home/serializers.py b/lms/djangoapps/learner_home/serializers.py index b9243a86d70a..3ddd884be97d 100644 --- a/lms/djangoapps/learner_home/serializers.py +++ b/lms/djangoapps/learner_home/serializers.py @@ -10,6 +10,7 @@ from django.utils import timezone from opaque_keys.edx.keys import CourseKey from rest_framework import serializers +from openedx_filters.learning.filters import CourseEnrollmentAPIRenderStarted from common.djangoapps.course_modes.models import CourseMode from openedx.features.course_experience import course_home_url @@ -244,6 +245,15 @@ def get_isEmailEnabled(self, enrollment): def get_hasOptedOutOfEmail(self, enrollment): return enrollment.course_id in self.context.get("course_optouts", []) + def to_representation(self, instance): + """Serialize the enrollment instance to be able to update the values before the API finishes rendering.""" + serialized_enrollment = super().to_representation(instance) + course_key, serialized_enrollment = CourseEnrollmentAPIRenderStarted().run_filter( + course_key=instance.course_id, + serialized_enrollment=serialized_enrollment, + ) + return serialized_enrollment + class GradeDataSerializer(serializers.Serializer): """Info about grades for this enrollment"""