diff --git a/common/djangoapps/student/views.py b/common/djangoapps/student/views.py index bca8ff9d76..a2369574d2 100644 --- a/common/djangoapps/student/views.py +++ b/common/djangoapps/student/views.py @@ -672,9 +672,12 @@ def change_name_request(request): pnc.rationale = request.POST['rationale'] if len(pnc.new_name) < 2: return HttpResponse(json.dumps({'success': False, 'error': 'Name required'})) - if len(pnc.rationale) < 2: - return HttpResponse(json.dumps({'success': False, 'error': 'Rationale required'})) pnc.save() + + # The following automatically accepts name change requests. Remove this to + # go back to the old system where it gets queued up for admin approval. + accept_name_change_by_id(pnc.id) + return HttpResponse(json.dumps({'success': True})) @@ -709,14 +712,9 @@ def reject_name_change(request): return HttpResponse(json.dumps({'success': True})) -@ensure_csrf_cookie -def accept_name_change(request): - ''' JSON: Name change process. Course staff clicks 'accept' on a given name change ''' - if not request.user.is_staff: - raise Http404 - +def accept_name_change_by_id(id): try: - pnc = PendingNameChange.objects.get(id=int(request.POST['id'])) + pnc = PendingNameChange.objects.get(id=id) except PendingNameChange.DoesNotExist: return HttpResponse(json.dumps({'success': False, 'error': 'Invalid ID'})) @@ -735,3 +733,12 @@ def accept_name_change(request): pnc.delete() return HttpResponse(json.dumps({'success': True})) + + +@ensure_csrf_cookie +def accept_name_change(request): + ''' JSON: Name change process. Course staff clicks 'accept' on a given name change ''' + if not request.user.is_staff: + raise Http404 + + return accept_name_change_by_id(int(request.POST['id'])) diff --git a/lms/templates/dashboard.html b/lms/templates/dashboard.html index 9b59dc2cd9..3fdcbb5c1c 100644 --- a/lms/templates/dashboard.html +++ b/lms/templates/dashboard.html @@ -46,16 +46,33 @@ function(data) { if (data.success) { $("#change_email_title").html("Please verify your new email"); - $("#change_email_body").html("
You'll receive a confirmation in your " + + $("#change_email_form").html("
You'll receive a confirmation in your " + "in-box. Please click the link in the " + "email to confirm the email change.
"); } else { - $("#change_email_error").html(data.error); + $("#change_email_error").html(data.error).stop().css("display", "block"); } }); return false; }); + $("#change_name_form").submit(function(){ + var new_name = $('#new_name_field').val(); + var rationale = $('#name_rationale_field').val(); + + $.post('${reverse("change_name")}', + {"new_name":new_name, "rationale":rationale}, + function(data) { + if(data.success) { + location.reload(); + // $("#change_name_body").html("Name changed.
"); + } else { + $("#change_name_error").html(data.error).stop().css("display", "block"); + } + }); + return false; + }); + })(this) %block> @@ -75,13 +92,13 @@