From edc32180fba76acf571210d39ec073ddf3e72579 Mon Sep 17 00:00:00 2001 From: Sagirov Evgeniy <34642612+UvgenGen@users.noreply.github.com> Date: Sun, 31 Mar 2024 16:00:48 +0300 Subject: [PATCH] feat: [ACI-513, ACI-519] Emit CCX course FAILING/PASSING status (#2526) Co-authored-by: Sagirov Eugeniy --- lms/djangoapps/grades/events.py | 113 ++++++++++++++++++++++---------- 1 file changed, 78 insertions(+), 35 deletions(-) diff --git a/lms/djangoapps/grades/events.py b/lms/djangoapps/grades/events.py index 9e648fa04ec7..7a02bb7d7bb5 100644 --- a/lms/djangoapps/grades/events.py +++ b/lms/djangoapps/grades/events.py @@ -6,7 +6,14 @@ from crum import get_current_user from django.conf import settings from eventtracking import tracker -from openedx_events.learning.data import CcxCoursePassingStatusData, CourseData, CoursePassingStatusData, UserData, UserPersonalData +from openedx_events.learning.data import ( + CcxCourseData, + CcxCoursePassingStatusData, + CourseData, + CoursePassingStatusData, + UserData, + UserPersonalData +) from openedx_events.learning.signals import CCX_COURSE_PASSING_STATUS_UPDATED, COURSE_PASSING_STATUS_UPDATED from common.djangoapps.course_modes.models import CourseMode @@ -193,25 +200,43 @@ def course_grade_now_passed(user, course_id): ) # produce to event bus - COURSE_PASSING_STATUS_UPDATED.send_event( - course_passing_status=CoursePassingStatusData( - status=CoursePassingStatusData.PASSING, - user=UserData( - pii=UserPersonalData( - username=user.username, - email=user.email, - name=user.get_full_name(), + if hasattr(course_id, 'ccx'): + CCX_COURSE_PASSING_STATUS_UPDATED.send_event( + course_passing_status=CcxCoursePassingStatusData( + status=CcxCoursePassingStatusData.PASSING, + user=UserData( + pii=UserPersonalData( + username=user.username, + email=user.email, + name=user.get_full_name(), + ), + id=user.id, + is_active=user.is_active, + ), + course=CcxCourseData( + ccx_course_key=course_id, + master_course_key=course_id.to_course_locator(), ), - id=user.id, - is_active=user.is_active, - ), - course=CourseData( - course_key=course_id, - ), - update_timestamp=None, - grading_policy_hash=None, + ) + ) + else: + COURSE_PASSING_STATUS_UPDATED.send_event( + course_passing_status=CoursePassingStatusData( + status=CoursePassingStatusData.PASSING, + user=UserData( + pii=UserPersonalData( + username=user.username, + email=user.email, + name=user.get_full_name(), + ), + id=user.id, + is_active=user.is_active, + ), + course=CourseData( + course_key=course_id, + ), + ) ) - ) def course_grade_now_failed(user, course_id): @@ -233,25 +258,43 @@ def course_grade_now_failed(user, course_id): ) # produce to event bus - COURSE_PASSING_STATUS_UPDATED.send_event( - course_passing_status=CoursePassingStatusData( - status = CoursePassingStatusData.FAILING, - user=UserData( - pii=UserPersonalData( - username=user.username, - email=user.email, - name=user.get_full_name(), + if hasattr(course_id, 'ccx'): + CCX_COURSE_PASSING_STATUS_UPDATED.send_event( + course_passing_status=CcxCoursePassingStatusData( + status=CcxCoursePassingStatusData.FAILING, + user=UserData( + pii=UserPersonalData( + username=user.username, + email=user.email, + name=user.get_full_name(), + ), + id=user.id, + is_active=user.is_active, ), - id=user.id, - is_active=user.is_active, - ), - course=CourseData( - course_key=course_id, - ), - update_timestamp=None, - grading_policy_hash=None, + course=CcxCourseData( + ccx_course_key=course_id, + master_course_key=course_id.to_course_locator(), + ), + ) + ) + else: + COURSE_PASSING_STATUS_UPDATED.send_event( + course_passing_status=CoursePassingStatusData( + status = CoursePassingStatusData.FAILING, + user=UserData( + pii=UserPersonalData( + username=user.username, + email=user.email, + name=user.get_full_name(), + ), + id=user.id, + is_active=user.is_active, + ), + course=CourseData( + course_key=course_id, + ), + ) ) - ) def fire_segment_event_on_course_grade_passed_first_time(user_id, course_locator):