summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJannis Leidel <jannis@leidel.info>2012-02-09 18:56:32 +0000
committerJannis Leidel <jannis@leidel.info>2012-02-09 18:56:32 +0000
commitb46d90c63ad866d5d7d6b09d8986339e0842550d (patch)
tree138cbe9743c860f0dbe8204fdcb2ddd1891175e5
parent03eeb020a00dedba2594326bd606d8b41d51e80f (diff)
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
-rw-r--r--django/contrib/admin/options.py4
-rw-r--r--django/contrib/auth/admin.py4
-rwxr-xr-xtests/regressiontests/admin_views/tests.py25
-rw-r--r--tests/regressiontests/admin_views/urls.py1
4 files changed, 31 insertions, 3 deletions
diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py
index 5bfa891a69..21eced0fb0 100644
--- a/django/contrib/admin/options.py
+++ b/django/contrib/admin/options.py
@@ -1011,7 +1011,7 @@ class ModelAdmin(BaseModelAdmin):
@csrf_protect_m
@transaction.commit_on_success
- def change_view(self, request, object_id, extra_context=None):
+ def change_view(self, request, object_id, form_url='', extra_context=None):
"The 'change' admin view for this model."
model = self.model
opts = model._meta
@@ -1099,7 +1099,7 @@ class ModelAdmin(BaseModelAdmin):
'app_label': opts.app_label,
}
context.update(extra_context or {})
- return self.render_change_form(request, context, change=True, obj=obj)
+ return self.render_change_form(request, context, change=True, obj=obj, form_url=form_url)
@csrf_protect_m
def changelist_view(self, request, extra_context=None):
diff --git a/django/contrib/auth/admin.py b/django/contrib/auth/admin.py
index 5e9ac9d0a9..dbcf52d778 100644
--- a/django/contrib/auth/admin.py
+++ b/django/contrib/auth/admin.py
@@ -11,6 +11,7 @@ from django.shortcuts import get_object_or_404
from django.template.response import TemplateResponse
from django.utils.html import escape
from django.utils.decorators import method_decorator
+from django.utils.safestring import mark_safe
from django.utils.translation import ugettext, ugettext_lazy as _
from django.views.decorators.csrf import csrf_protect
from django.views.decorators.debug import sensitive_post_parameters
@@ -113,7 +114,7 @@ class UserAdmin(admin.ModelAdmin):
extra_context)
@sensitive_post_parameters()
- def user_change_password(self, request, id):
+ def user_change_password(self, request, id, form_url=''):
if not self.has_change_permission(request):
raise PermissionDenied
user = get_object_or_404(self.model, pk=id)
@@ -133,6 +134,7 @@ class UserAdmin(admin.ModelAdmin):
context = {
'title': _('Change password: %s') % escape(user.username),
'adminForm': adminForm,
+ 'form_url': mark_safe(form_url),
'form': form,
'is_popup': '_popup' in request.REQUEST,
'add': True,
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
index 6b001e97ab..574c6f6138 100755
--- a/tests/regressiontests/admin_views/tests.py
+++ b/tests/regressiontests/admin_views/tests.py
@@ -574,6 +574,25 @@ class AdminViewBasicTest(TestCase):
self.fail("Filters should be allowed if they are defined on a ForeignKey pointing to this model")
+class AdminViewFormUrlTest(TestCase):
+ urls = "regressiontests.admin_views.urls"
+ fixtures = ["admin-views-users.xml"]
+ urlbit = "admin3"
+
+ def setUp(self):
+ self.client.login(username='super', password='secret')
+
+ def tearDown(self):
+ self.client.logout()
+
+ def testChangeFormUrlHasCorrectValue(self):
+ """
+ Tests whether change_view has form_url in request.context
+ """
+ response = self.client.get('/test_admin/%s/admin_views/section/1/' % self.urlbit)
+ self.assertTrue('form_url' in response.context, msg='form_url not present in response.context')
+ self.assertEqual(response.context['form_url'], 'pony')
+
class AdminJavaScriptTest(AdminViewBasicTest):
urls = "regressiontests.admin_views.urls"
@@ -3054,6 +3073,12 @@ class UserAdminTest(TestCase):
response = self.client.get('/test_admin/admin/auth/user/%s/' % u.pk)
self.assertEqual(response.status_code, 200)
+ def test_form_url_present_in_context(self):
+ u = User.objects.all()[0]
+ response = self.client.get('/test_admin/admin3/auth/user/%s/password/' % u.pk)
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.context['form_url'], 'pony')
+
class GroupAdminTest(TestCase):
"""
diff --git a/tests/regressiontests/admin_views/urls.py b/tests/regressiontests/admin_views/urls.py
index 03bfbf0812..da6e2cbcf9 100644
--- a/tests/regressiontests/admin_views/urls.py
+++ b/tests/regressiontests/admin_views/urls.py
@@ -10,4 +10,5 @@ urlpatterns = patterns('',
(r'^test_admin/admin/secure-view/$', views.secure_view),
(r'^test_admin/admin/', include(admin.site.urls)),
(r'^test_admin/admin2/', include(customadmin.site.urls)),
+ (r'^test_admin/admin3/', include(admin.site.urls), dict(form_url='pony')),
)