Code

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, 6 years ago)

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

Line 
1Index: django/contrib/auth/views.py
2===================================================================
3--- django/contrib/auth/views.py        (revision 8471)
4+++ django/contrib/auth/views.py        (working copy)
5@@ -4,7 +4,7 @@
6 from django.contrib.auth.forms import AuthenticationForm
7 from django.contrib.auth.forms import PasswordResetForm, SetPasswordForm, PasswordChangeForm
8 from django.contrib.auth.tokens import default_token_generator
9-from django.core.urlresolvers import reverse
10+from django.core.urlresolvers import reverse, NoReverseMatch
11 from django.shortcuts import render_to_response, get_object_or_404
12 from django.contrib.sites.models import Site, RequestSite
13 from django.http import HttpResponseRedirect, Http404
14@@ -136,7 +136,13 @@
15         form = PasswordChangeForm(request.user, request.POST)
16         if form.is_valid():
17             form.save()
18-            return HttpResponseRedirect(reverse('django.contrib.auth.views.password_change_done'))
19+            try:
20+                return HttpResponseRedirect(reverse('django.contrib.auth.views.password_change_done'))
21+            except NoReverseMatch:
22+                # Admin interfaces don't hook contrib.auth urls into anything
23+                # that reverse() can find, so we do something absurdly hackish
24+                # here so we don't have to rewrite the entirety of admin.sites.root
25+                return HttpResponseRedirect('done/')
26     else:
27         form = PasswordChangeForm(request.user)
28     return render_to_response(template_name, {