Learner Profile page tweaks.
TNL-2047
This commit is contained in:
@@ -10,6 +10,10 @@ from django.http import HttpResponse
|
||||
from django.views.decorators.http import require_http_methods
|
||||
|
||||
from edxmako.shortcuts import render_to_response
|
||||
from openedx.core.djangoapps.user_api.preferences.api import get_user_preferences
|
||||
from openedx.core.djangoapps.user_api.accounts.api import get_account_settings
|
||||
from openedx.core.djangoapps.user_api.errors import UserNotFound, UserNotAuthorized
|
||||
from openedx.core.djangoapps.user_api.accounts.serializers import PROFILE_IMAGE_KEY_PREFIX
|
||||
from student.models import User
|
||||
|
||||
from microsite_configuration import microsite
|
||||
@@ -38,13 +42,17 @@ def learner_profile(request, username):
|
||||
try:
|
||||
return render_to_response(
|
||||
'student_profile/learner_profile.html',
|
||||
learner_profile_context(request.user.username, username, request.user.is_staff)
|
||||
learner_profile_context(request, request.user.username, username, request.user.is_staff)
|
||||
)
|
||||
except UserNotAuthorized:
|
||||
return HttpResponse(status=403)
|
||||
except UserNotFound:
|
||||
return HttpResponse(status=404)
|
||||
except ObjectDoesNotExist:
|
||||
return HttpResponse(status=404)
|
||||
|
||||
|
||||
def learner_profile_context(logged_in_username, profile_username, user_is_staff):
|
||||
def learner_profile_context(request, logged_in_username, profile_username, user_is_staff):
|
||||
"""Context for the learner profile page.
|
||||
|
||||
Args:
|
||||
@@ -67,6 +75,16 @@ def learner_profile_context(logged_in_username, profile_username, user_is_staff)
|
||||
)
|
||||
]
|
||||
|
||||
own_profile = (logged_in_username == profile_username)
|
||||
|
||||
accounts_data = get_account_settings(request.user, profile_username)
|
||||
# Account for possibly relative URLs.
|
||||
for key, value in accounts_data['profile_image'].items():
|
||||
if key.startswith(PROFILE_IMAGE_KEY_PREFIX):
|
||||
accounts_data['profile_image'][key] = request.build_absolute_uri(value)
|
||||
|
||||
preferences_data = get_user_preferences(profile_user, profile_username)
|
||||
|
||||
context = {
|
||||
'data': {
|
||||
'profile_user_id': profile_user.id,
|
||||
@@ -74,17 +92,18 @@ def learner_profile_context(logged_in_username, profile_username, user_is_staff)
|
||||
'default_visibility': settings.ACCOUNT_VISIBILITY_CONFIGURATION['default_visibility'],
|
||||
'accounts_api_url': reverse("accounts_api", kwargs={'username': profile_username}),
|
||||
'preferences_api_url': reverse('preferences_api', kwargs={'username': profile_username}),
|
||||
'preferences_data': preferences_data,
|
||||
'accounts_data': accounts_data,
|
||||
'profile_image_upload_url': reverse('profile_image_upload', kwargs={'username': profile_username}),
|
||||
'profile_image_remove_url': reverse('profile_image_remove', kwargs={'username': profile_username}),
|
||||
'profile_image_max_bytes': settings.PROFILE_IMAGE_MAX_BYTES,
|
||||
'profile_image_min_bytes': settings.PROFILE_IMAGE_MIN_BYTES,
|
||||
'account_settings_page_url': reverse('account_settings'),
|
||||
'has_preferences_access': (logged_in_username == profile_username or user_is_staff),
|
||||
'own_profile': (logged_in_username == profile_username),
|
||||
'own_profile': own_profile,
|
||||
'country_options': country_options,
|
||||
'language_options': settings.ALL_LANGUAGES,
|
||||
'platform_name': microsite.get_value('platform_name', settings.PLATFORM_NAME),
|
||||
}
|
||||
}
|
||||
|
||||
return context
|
||||
|
||||
@@ -16,18 +16,19 @@
|
||||
|
||||
var learnerProfileElement = $('.wrapper-profile');
|
||||
var defaultVisibility = options.default_visibility;
|
||||
var AccountPreferencesModelWithDefaults = AccountPreferencesModel.extend({
|
||||
defaults: {
|
||||
account_privacy: defaultVisibility
|
||||
}
|
||||
});
|
||||
var accountPreferencesModel = new AccountPreferencesModelWithDefaults();
|
||||
accountPreferencesModel.url = options.preferences_api_url;
|
||||
var accountPreferencesModel, accountSettingsModel;
|
||||
|
||||
var accountSettingsModel = new AccountSettingsModel({
|
||||
'default_public_account_fields': options.default_public_account_fields
|
||||
});
|
||||
if (options.own_profile) {
|
||||
accountSettingsModel = new AccountSettingsModel({
|
||||
'default_public_account_fields': options.default_public_account_fields
|
||||
});
|
||||
accountPreferencesModel = new AccountPreferencesModel({account_privacy: defaultVisibility});
|
||||
} else {
|
||||
accountSettingsModel = new AccountSettingsModel(options.accounts_data, {parse: true});
|
||||
accountPreferencesModel = new AccountPreferencesModel(options.preferences_data);
|
||||
}
|
||||
accountSettingsModel.url = options.accounts_api_url;
|
||||
accountPreferencesModel.url = options.preferences_api_url;
|
||||
|
||||
var editable = options.own_profile ? 'toggle' : 'never';
|
||||
|
||||
@@ -146,26 +147,34 @@
|
||||
learnerProfileView.render();
|
||||
};
|
||||
|
||||
accountSettingsModel.fetch({
|
||||
success: function () {
|
||||
// Fetch the preferences model if the user has access
|
||||
if (options.has_preferences_access) {
|
||||
accountPreferencesModel.fetch({
|
||||
success: function() {
|
||||
if (accountSettingsModel.get('requires_parental_consent')) {
|
||||
accountPreferencesModel.set('account_privacy', 'private');
|
||||
}
|
||||
showLearnerProfileView();
|
||||
},
|
||||
error: showLoadingError
|
||||
});
|
||||
if (options.own_profile) {
|
||||
accountSettingsModel.fetch({
|
||||
success: function () {
|
||||
// Fetch the preferences model if the user has access
|
||||
if (options.has_preferences_access) {
|
||||
accountPreferencesModel.fetch({
|
||||
success: function () {
|
||||
if (accountSettingsModel.get('requires_parental_consent')) {
|
||||
accountPreferencesModel.set('account_privacy', 'private');
|
||||
}
|
||||
showLearnerProfileView();
|
||||
},
|
||||
error: showLoadingError
|
||||
});
|
||||
} else {
|
||||
showLearnerProfileView();
|
||||
}
|
||||
},
|
||||
error: showLoadingError
|
||||
});
|
||||
} else {
|
||||
if (options.has_preferences_access) {
|
||||
if (accountSettingsModel.get('requires_parental_consent')) {
|
||||
accountPreferencesModel.set('account_privacy', 'private');
|
||||
}
|
||||
else {
|
||||
showLearnerProfileView();
|
||||
}
|
||||
},
|
||||
error: showLoadingError
|
||||
});
|
||||
}
|
||||
showLearnerProfileView();
|
||||
}
|
||||
|
||||
return {
|
||||
accountSettingsModel: accountSettingsModel,
|
||||
|
||||
@@ -201,13 +201,15 @@
|
||||
this.$el.addClass('mode-edit');
|
||||
},
|
||||
|
||||
startEditing: function () {
|
||||
startEditing: function (event) {
|
||||
event.preventDefault();
|
||||
if (this.editable === 'toggle' && this.mode !== 'edit') {
|
||||
this.showEditMode(true);
|
||||
}
|
||||
},
|
||||
|
||||
finishEditing: function() {
|
||||
finishEditing: function(event) {
|
||||
event.preventDefault();
|
||||
if (this.fieldValue() !== this.modelValue()) {
|
||||
this.saveValue();
|
||||
} else {
|
||||
|
||||
@@ -218,7 +218,6 @@
|
||||
|
||||
.wrapper-profile-section-two {
|
||||
width: flex-grid(8, 12);
|
||||
margin-top: ($baseline*1.5);
|
||||
}
|
||||
|
||||
.profile-section-two-fields {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<%! import json %>
|
||||
<%! from django.core.urlresolvers import reverse %>
|
||||
<%! from django.utils.translation import ugettext as _ %>
|
||||
<%! from xmodule.modulestore import EdxJSONEncoder %>
|
||||
|
||||
<%inherit file="/main.html" />
|
||||
<%namespace name='static' file='/static_content.html'/>
|
||||
@@ -38,7 +39,7 @@
|
||||
<script>
|
||||
(function (require) {
|
||||
require(['js/student_profile/views/learner_profile_factory'], function(setupLearnerProfile) {
|
||||
var options = ${ json.dumps(data) };
|
||||
var options = ${ json.dumps(data, cls=EdxJSONEncoder) };
|
||||
setupLearnerProfile(options);
|
||||
});
|
||||
}).call(this, require || RequireJS.require);
|
||||
|
||||
Reference in New Issue
Block a user