From ab26efc95286fa3e7e52f5f9ec232055bcd2cbb7 Mon Sep 17 00:00:00 2001 From: Brian Rosner Date: Sat, 23 Aug 2008 03:26:01 +0000 Subject: [PATCH] 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 --- django/contrib/admin/sites.py | 3 ++- django/contrib/auth/views.py | 21 +++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py index 7e94bbf011..9d0c65d589 100644 --- a/django/contrib/admin/sites.py +++ b/django/contrib/admin/sites.py @@ -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): """ diff --git a/django/contrib/auth/views.py b/django/contrib/auth/views.py index 43693d6e20..e1f0d43c00 100644 --- a/django/contrib/auth/views.py +++ b/django/contrib/auth/views.py @@ -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, {