Fixed #8493 -- Fixed a NoReverseMatch when redirecting to password_change/done/ in the admin. Added the ability to override redirects to other password change views for consistency. Thanks for the report mtrichardson.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8473 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Brian Rosner 2008-08-23 03:26:01 +00:00
parent d4d7bc175d
commit ab26efc952
2 changed files with 17 additions and 7 deletions

View File

@ -194,7 +194,8 @@ class AdminSite(object):
Handles the "change password" task -- both form display and validation.
"""
from django.contrib.auth.views import password_change
return password_change(request)
return password_change(request,
post_save_redirect='%spassword_change/done/' % self.root_path)
def password_change_done(self, request):
"""

View File

@ -73,7 +73,10 @@ def redirect_to_login(next, login_url=None, redirect_field_name=REDIRECT_FIELD_N
def password_reset(request, is_admin_site=False, template_name='registration/password_reset_form.html',
email_template_name='registration/password_reset_email.html',
password_reset_form=PasswordResetForm, token_generator=default_token_generator):
password_reset_form=PasswordResetForm, token_generator=default_token_generator,
post_reset_redirect=None):
if post_reset_redirect is None:
post_reset_redirect = reverse('django.contrib.auth.views.password_reset_done')
if request.method == "POST":
form = password_reset_form(request.POST)
if form.is_valid():
@ -87,7 +90,7 @@ def password_reset(request, is_admin_site=False, template_name='registration/pas
if not Site._meta.installed:
opts['domain_override'] = RequestSite(request).domain
form.save(**opts)
return HttpResponseRedirect(reverse('django.contrib.auth.views.password_reset_done'))
return HttpResponseRedirect(post_reset_redirect)
else:
form = password_reset_form()
return render_to_response(template_name, {
@ -98,12 +101,15 @@ def password_reset_done(request, template_name='registration/password_reset_done
return render_to_response(template_name, context_instance=RequestContext(request))
def password_reset_confirm(request, uidb36=None, token=None, template_name='registration/password_reset_confirm.html',
token_generator=default_token_generator, set_password_form=SetPasswordForm):
token_generator=default_token_generator, set_password_form=SetPasswordForm,
post_reset_redirect=None):
"""
View that checks the hash in a password reset link and presents a
form for entering a new password.
"""
assert uidb36 is not None and token is not None # checked by URLconf
if post_reset_redirect is None:
post_reset_redirect = reverse('django.contrib.auth.views.password_reset_complete')
try:
uid_int = base36_to_int(uidb36)
except ValueError:
@ -118,7 +124,7 @@ def password_reset_confirm(request, uidb36=None, token=None, template_name='regi
form = set_password_form(user, request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse('django.contrib.auth.views.password_reset_complete'))
return HttpResponseRedirect(post_reset_redirect)
else:
form = set_password_form(None)
else:
@ -131,12 +137,15 @@ def password_reset_complete(request, template_name='registration/password_reset_
return render_to_response(template_name, context_instance=RequestContext(request,
{'login_url': settings.LOGIN_URL}))
def password_change(request, template_name='registration/password_change_form.html'):
def password_change(request, template_name='registration/password_change_form.html',
post_change_redirect=None):
if post_change_redirect is None:
post_change_redirect = reverse('django.contrib.auth.views.password_change_done')
if request.method == "POST":
form = PasswordChangeForm(request.user, request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse('django.contrib.auth.views.password_change_done'))
return HttpResponseRedirect(post_change_redirect)
else:
form = PasswordChangeForm(request.user)
return render_to_response(template_name, {