Ticket #8493: 8493.hackish_try_except_to_get_admin_working.diff

File 8493.hackish_try_except_to_get_admin_working.diff, 1.5 KB (added by mtrichardson, 8 years ago)

If there's a NoReverseMatch, catch it and HttpResponseRedirect to a relative path of 'done/'. *shudder*

  • django/contrib/auth/views.py

    44from django.contrib.auth.forms import AuthenticationForm
    55from django.contrib.auth.forms import PasswordResetForm, SetPasswordForm, PasswordChangeForm
    66from django.contrib.auth.tokens import default_token_generator
    7 from django.core.urlresolvers import reverse
     7from django.core.urlresolvers import reverse, NoReverseMatch
    88from django.shortcuts import render_to_response, get_object_or_404
    99from django.contrib.sites.models import Site, RequestSite
    1010from django.http import HttpResponseRedirect, Http404
    136136        form = PasswordChangeForm(request.user, request.POST)
    137137        if form.is_valid():
    138138            form.save()
    139             return HttpResponseRedirect(reverse('django.contrib.auth.views.password_change_done'))
     139            try:
     140                return HttpResponseRedirect(reverse('django.contrib.auth.views.password_change_done'))
     141            except NoReverseMatch:
     142                # Admin interfaces don't hook contrib.auth urls into anything
     143                # that reverse() can find, so we do something absurdly hackish
     144                # here so we don't have to rewrite the entirety of admin.sites.root
     145                return HttpResponseRedirect('done/')
    140146    else:
    141147        form = PasswordChangeForm(request.user)
    142148    return render_to_response(template_name, {
Back to Top