Implement profile API
TNL-1491 See the API design here: https://openedx.atlassian.net/wiki/display/TNL/User+API
This commit is contained in:
@@ -20,7 +20,7 @@ from django.contrib import messages
|
||||
from django.core.context_processors import csrf
|
||||
from django.core import mail
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.core.validators import validate_email, validate_slug, ValidationError
|
||||
from django.core.validators import validate_email, ValidationError
|
||||
from django.db import IntegrityError, transaction
|
||||
from django.http import (HttpResponse, HttpResponseBadRequest, HttpResponseForbidden,
|
||||
Http404)
|
||||
@@ -84,7 +84,6 @@ from external_auth.login_and_register import (
|
||||
|
||||
from bulk_email.models import Optout, CourseAuthorization
|
||||
import shoppingcart
|
||||
from openedx.core.djangoapps.user_api.models import UserPreference
|
||||
from lang_pref import LANGUAGE_KEY
|
||||
from notification_prefs.views import enable_notifications
|
||||
|
||||
@@ -113,7 +112,6 @@ from student.helpers import (
|
||||
)
|
||||
from xmodule.error_module import ErrorDescriptor
|
||||
from shoppingcart.models import DonationConfiguration, CourseRegistrationCode
|
||||
from openedx.core.djangoapps.user_api.api import profile as profile_api
|
||||
|
||||
from embargo import api as embargo_api
|
||||
|
||||
@@ -649,6 +647,9 @@ def dashboard(request):
|
||||
# Re-alphabetize language options
|
||||
language_options.sort()
|
||||
|
||||
# TODO: remove circular dependency on openedx from common
|
||||
from openedx.core.djangoapps.user_api.models import UserPreference
|
||||
|
||||
# try to get the prefered language for the user
|
||||
cur_pref_lang_code = UserPreference.get_preference(request.user, LANGUAGE_KEY)
|
||||
# try and get the current language of the user
|
||||
@@ -813,6 +814,10 @@ def try_change_enrollment(request):
|
||||
|
||||
def _update_email_opt_in(request, username, org):
|
||||
"""Helper function used to hit the profile API if email opt-in is enabled."""
|
||||
|
||||
# TODO: remove circular dependency on openedx from common
|
||||
from openedx.core.djangoapps.user_api.api import profile as profile_api
|
||||
|
||||
email_opt_in = request.POST.get('email_opt_in')
|
||||
if email_opt_in is not None:
|
||||
email_opt_in_boolean = email_opt_in == 'true'
|
||||
@@ -1401,6 +1406,9 @@ def _do_create_account(form):
|
||||
log.exception("UserProfile creation failed for user {id}.".format(id=user.id))
|
||||
raise
|
||||
|
||||
# TODO: remove circular dependency on openedx from common
|
||||
from openedx.core.djangoapps.user_api.models import UserPreference
|
||||
|
||||
UserPreference.set_preference(user, LANGUAGE_KEY, get_language())
|
||||
|
||||
return (user, profile, registration)
|
||||
|
||||
@@ -103,8 +103,6 @@ from . import provider
|
||||
# `AUTH_ENROLL_COURSE_ID_KEY` provides the course ID that a student
|
||||
# is trying to enroll in, used to generate analytics events
|
||||
# and auto-enroll students.
|
||||
from openedx.core.djangoapps.user_api.api import profile
|
||||
|
||||
AUTH_ENTRY_KEY = 'auth_entry'
|
||||
AUTH_REDIRECT_KEY = 'next'
|
||||
AUTH_ENROLL_COURSE_ID_KEY = 'enroll_course_id'
|
||||
@@ -671,6 +669,8 @@ def change_enrollment(strategy, user=None, is_dashboard=False, *args, **kwargs):
|
||||
# If the email opt in parameter is found, set the preference.
|
||||
email_opt_in = strategy.session_get(AUTH_EMAIL_OPT_IN_KEY)
|
||||
if email_opt_in:
|
||||
# TODO: remove circular dependency on openedx from common
|
||||
from openedx.core.djangoapps.user_api.api import profile
|
||||
opt_in = email_opt_in.lower() == 'true'
|
||||
profile.update_email_opt_in(user.username, course_id.org, opt_in)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user