diff --git a/common/djangoapps/student/models_api.py b/common/djangoapps/student/models_api.py index e093b0b7f0..3c6a9732ef 100644 --- a/common/djangoapps/student/models_api.py +++ b/common/djangoapps/student/models_api.py @@ -1,6 +1,7 @@ """ Provides Python APIs exposed from Student models. """ +import logging from student.models import CourseEnrollment as _CourseEnrollment from student.models import ManualEnrollmentAudit as _ManualEnrollmentAudit @@ -14,6 +15,7 @@ from student.models import ( ALLOWEDTOENROLL_TO_UNENROLLED as _ALLOWEDTOENROLL_TO_UNENROLLED, DEFAULT_TRANSITION_STATE as _DEFAULT_TRANSITION_STATE, ) +from student.models import UserProfile as _UserProfile # This is done so that if these strings change within the app, we can keep exported constants the same ENROLLED_TO_ENROLLED = _ENROLLED_TO_ENROLLED @@ -24,6 +26,7 @@ UNENROLLED_TO_ALLOWEDTOENROLL = _UNENROLLED_TO_ALLOWEDTOENROLL ALLOWEDTOENROLL_TO_ENROLLED = _ALLOWEDTOENROLL_TO_ENROLLED ALLOWEDTOENROLL_TO_UNENROLLED = _ALLOWEDTOENROLL_TO_UNENROLLED DEFAULT_TRANSITION_STATE = _DEFAULT_TRANSITION_STATE +log = logging.getLogger(__name__) def create_manual_enrollment_audit( @@ -46,3 +49,16 @@ def create_manual_enrollment_audit( def get_course_enrollment(user, course_run_key): return _CourseEnrollment.get_enrollment(user, course_run_key) + + +def get_phone_number(user_id): + """ + Get a users phone number from the profile, if + one exists. Otherwise, return None. + """ + try: + student = _UserProfile.objects.get(user_id=user_id) + except _UserProfile.DoesNotExist as exception: + log.exception(exception) + return None + return student.phone_number or None