Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #7758 and #17189 -- Allowed to override the `form_url` context …

…var in the admin change view and the user admin's password change view. Thanks, michal and krzysztof.szczesny.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17466 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit b46d90c63ad866d5d7d6b09d8986339e0842550d 1 parent 03eeb02
Jannis Leidel authored February 09, 2012
4  django/contrib/admin/options.py
@@ -1011,7 +1011,7 @@ def add_view(self, request, form_url='', extra_context=None):
1011 1011
 
1012 1012
     @csrf_protect_m
1013 1013
     @transaction.commit_on_success
1014  
-    def change_view(self, request, object_id, extra_context=None):
  1014
+    def change_view(self, request, object_id, form_url='', extra_context=None):
1015 1015
         "The 'change' admin view for this model."
1016 1016
         model = self.model
1017 1017
         opts = model._meta
@@ -1099,7 +1099,7 @@ def change_view(self, request, object_id, extra_context=None):
1099 1099
             'app_label': opts.app_label,
1100 1100
         }
1101 1101
         context.update(extra_context or {})
1102  
-        return self.render_change_form(request, context, change=True, obj=obj)
  1102
+        return self.render_change_form(request, context, change=True, obj=obj, form_url=form_url)
1103 1103
 
1104 1104
     @csrf_protect_m
1105 1105
     def changelist_view(self, request, extra_context=None):
4  django/contrib/auth/admin.py
@@ -11,6 +11,7 @@
11 11
 from django.template.response import TemplateResponse
12 12
 from django.utils.html import escape
13 13
 from django.utils.decorators import method_decorator
  14
+from django.utils.safestring import mark_safe
14 15
 from django.utils.translation import ugettext, ugettext_lazy as _
15 16
 from django.views.decorators.csrf import csrf_protect
16 17
 from django.views.decorators.debug import sensitive_post_parameters
@@ -113,7 +114,7 @@ def add_view(self, request, form_url='', extra_context=None):
113 114
                                                extra_context)
114 115
 
115 116
     @sensitive_post_parameters()
116  
-    def user_change_password(self, request, id):
  117
+    def user_change_password(self, request, id, form_url=''):
117 118
         if not self.has_change_permission(request):
118 119
             raise PermissionDenied
119 120
         user = get_object_or_404(self.model, pk=id)
@@ -133,6 +134,7 @@ def user_change_password(self, request, id):
133 134
         context = {
134 135
             'title': _('Change password: %s') % escape(user.username),
135 136
             'adminForm': adminForm,
  137
+            'form_url': mark_safe(form_url),
136 138
             'form': form,
137 139
             'is_popup': '_popup' in request.REQUEST,
138 140
             'add': True,
25  tests/regressiontests/admin_views/tests.py
@@ -574,6 +574,25 @@ def test_allowed_filtering_15103(self):
574 574
             self.fail("Filters should be allowed if they are defined on a ForeignKey pointing to this model")
575 575
 
576 576
 
  577
+class AdminViewFormUrlTest(TestCase):
  578
+    urls = "regressiontests.admin_views.urls"
  579
+    fixtures = ["admin-views-users.xml"]
  580
+    urlbit = "admin3"
  581
+
  582
+    def setUp(self):
  583
+        self.client.login(username='super', password='secret')
  584
+
  585
+    def tearDown(self):
  586
+        self.client.logout()
  587
+
  588
+    def testChangeFormUrlHasCorrectValue(self):
  589
+        """
  590
+        Tests whether change_view has form_url in request.context
  591
+        """
  592
+        response = self.client.get('/test_admin/%s/admin_views/section/1/' % self.urlbit)
  593
+        self.assertTrue('form_url' in response.context, msg='form_url not present in response.context')
  594
+        self.assertEqual(response.context['form_url'], 'pony')
  595
+
577 596
 class AdminJavaScriptTest(AdminViewBasicTest):
578 597
     urls = "regressiontests.admin_views.urls"
579 598
 
@@ -3054,6 +3073,12 @@ def test_user_permission_performance(self):
3054 3073
             response = self.client.get('/test_admin/admin/auth/user/%s/' % u.pk)
3055 3074
             self.assertEqual(response.status_code, 200)
3056 3075
 
  3076
+    def test_form_url_present_in_context(self):
  3077
+        u = User.objects.all()[0]
  3078
+        response = self.client.get('/test_admin/admin3/auth/user/%s/password/' % u.pk)
  3079
+        self.assertEqual(response.status_code, 200)
  3080
+        self.assertEqual(response.context['form_url'], 'pony')
  3081
+
3057 3082
 
3058 3083
 class GroupAdminTest(TestCase):
3059 3084
     """
1  tests/regressiontests/admin_views/urls.py
@@ -10,4 +10,5 @@
10 10
     (r'^test_admin/admin/secure-view/$', views.secure_view),
11 11
     (r'^test_admin/admin/', include(admin.site.urls)),
12 12
     (r'^test_admin/admin2/', include(customadmin.site.urls)),
  13
+    (r'^test_admin/admin3/', include(admin.site.urls), dict(form_url='pony')),
13 14
 )

0 notes on commit b46d90c

Please sign in to comment.
Something went wrong with that request. Please try again.