From b8faf7324115a0f36e5206b6c8e104eadba04ca6 Mon Sep 17 00:00:00 2001 From: Felipe Montoya Date: Fri, 30 Aug 2024 16:41:23 -0500 Subject: [PATCH 1/2] feat: show exception message from filters in the user interface --- common/djangoapps/student/models/course_enrollment.py | 2 ++ common/djangoapps/student/views/management.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/common/djangoapps/student/models/course_enrollment.py b/common/djangoapps/student/models/course_enrollment.py index 750ac66e38c0..6d32ffca4149 100644 --- a/common/djangoapps/student/models/course_enrollment.py +++ b/common/djangoapps/student/models/course_enrollment.py @@ -717,6 +717,8 @@ def enroll(cls, user, course_key, mode=None, check_access=False, can_upgrade=Fal Also emits relevant events for analytics purposes. """ try: + # .. filter_implemented_name: CourseEnrollmentStarted + # .. filter_type: org.openedx.learning.course.enrollment.started.v1 user, course_key, mode = CourseEnrollmentStarted.run_filter( user=user, course_key=course_key, mode=mode, ) diff --git a/common/djangoapps/student/views/management.py b/common/djangoapps/student/views/management.py index b06cac7b7e50..0f8be8ff9b56 100644 --- a/common/djangoapps/student/views/management.py +++ b/common/djangoapps/student/views/management.py @@ -70,6 +70,7 @@ from common.djangoapps.student.models import ( # lint-amnesty, pylint: disable=unused-import AccountRecovery, CourseEnrollment, + EnrollmentNotAllowed, PendingEmailChange, # unimport:skip PendingSecondaryEmailChange, Registration, @@ -422,6 +423,8 @@ def change_enrollment(request, check_access=True): enroll_mode = CourseMode.auto_enroll_mode(course_id, available_modes) if enroll_mode: CourseEnrollment.enroll(user, course_id, check_access=check_access, mode=enroll_mode) + except EnrollmentNotAllowed as exec: # pylint: disable=broad-except + return HttpResponseBadRequest(str(exec)) except Exception: # pylint: disable=broad-except return HttpResponseBadRequest(_("Could not enroll")) From f1a84a549225813d0731ed6a791cf2e907234e16 Mon Sep 17 00:00:00 2001 From: Maria Grimaldi Date: Tue, 10 Dec 2024 23:30:21 +0100 Subject: [PATCH 2/2] fix: remove unnecessary pylint suppression --- common/djangoapps/student/views/management.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/djangoapps/student/views/management.py b/common/djangoapps/student/views/management.py index 0f8be8ff9b56..02940da78f3b 100644 --- a/common/djangoapps/student/views/management.py +++ b/common/djangoapps/student/views/management.py @@ -423,8 +423,8 @@ def change_enrollment(request, check_access=True): enroll_mode = CourseMode.auto_enroll_mode(course_id, available_modes) if enroll_mode: CourseEnrollment.enroll(user, course_id, check_access=check_access, mode=enroll_mode) - except EnrollmentNotAllowed as exec: # pylint: disable=broad-except - return HttpResponseBadRequest(str(exec)) + except EnrollmentNotAllowed as exc: + return HttpResponseBadRequest(str(exc)) except Exception: # pylint: disable=broad-except return HttpResponseBadRequest(_("Could not enroll"))