MICROBA-253 add phone number field api for coaching plugin (#23406)

* MICROBA-253 add phone number field api for coaching plugin

* Remove hardcoded value

* Requested changes

* Add logger to models_api.py for student
* Import model with underscore to prevent exporting
* Moved return outside of try/catch block

* Add docstring

* whitespace
This commit is contained in:
Thomas Tracy
2020-03-17 11:52:27 -04:00
committed by GitHub
parent 8219ddc40a
commit 4d9f20689a

View File

@@ -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