From c8dcded930a1d0ee5688ae2c2eeb8c33d942009f Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Sat, 29 Nov 2014 08:19:59 +0200 Subject: [PATCH] Fixed #17890 -- Added an extra_context parameter to AdminSite.password_change(). --- django/contrib/admin/sites.py | 4 ++-- docs/releases/1.8.txt | 3 +++ tests/admin_views/customadmin.py | 3 +++ tests/admin_views/tests.py | 6 ++++++ tests/templates/custom_admin/password_change_form.html | 1 + 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py index e310635eeaf..3a69afda4a6 100644 --- a/django/contrib/admin/sites.py +++ b/django/contrib/admin/sites.py @@ -281,7 +281,7 @@ class AdminSite(object): 'site_url': self.site_url, } - def password_change(self, request): + def password_change(self, request, extra_context=None): """ Handles the "change password" task -- both form display and validation. """ @@ -292,7 +292,7 @@ class AdminSite(object): 'current_app': self.name, 'password_change_form': AdminPasswordChangeForm, 'post_change_redirect': url, - 'extra_context': self.each_context(), + 'extra_context': dict(self.each_context(), **(extra_context or {})), } if self.password_change_template is not None: defaults['template_name'] = self.password_change_template diff --git a/docs/releases/1.8.txt b/docs/releases/1.8.txt index 2a1ec35873f..28b0770aa9f 100644 --- a/docs/releases/1.8.txt +++ b/docs/releases/1.8.txt @@ -100,6 +100,9 @@ Minor features ` to control whether or not the full count of objects should be displayed on a filtered admin page. +* The ``AdminSite.password_change()`` method now has an ``extra_context`` + parameter. + :mod:`django.contrib.admindocs` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/admin_views/customadmin.py b/tests/admin_views/customadmin.py index 906fb871db8..3276a3091d6 100644 --- a/tests/admin_views/customadmin.py +++ b/tests/admin_views/customadmin.py @@ -33,6 +33,9 @@ class Admin2(admin.AdminSite): def my_view(self, request): return HttpResponse("Django is a magical pony!") + def password_change(self, request, extra_context=None): + return super(Admin2, self).password_change(request, {'spam': 'eggs'}) + class UserLimitedAdmin(UserAdmin): # used for testing password change on a user not in queryset diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index f55bcacd782..6313fdfd088 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -1012,6 +1012,12 @@ class CustomModelAdminTest(AdminViewBasicTestCase): self.assertTemplateUsed(response, 'custom_admin/password_change_form.html') self.assertContains(response, 'Hello from a custom password change form template') + def test_custom_admin_site_password_change_with_extra_context(self): + response = self.client.get('/test_admin/admin2/password_change/') + self.assertIsInstance(response, TemplateResponse) + self.assertTemplateUsed(response, 'custom_admin/password_change_form.html') + self.assertContains(response, 'eggs') + def test_custom_admin_site_password_change_done_template(self): response = self.client.get('/test_admin/admin2/password_change/done/') self.assertIsInstance(response, TemplateResponse) diff --git a/tests/templates/custom_admin/password_change_form.html b/tests/templates/custom_admin/password_change_form.html index 1c424934e44..12d911002e6 100644 --- a/tests/templates/custom_admin/password_change_form.html +++ b/tests/templates/custom_admin/password_change_form.html @@ -1,6 +1,7 @@ {% extends "registration/password_change_form.html" %} {% block content %} +{{ spam }} Hello from a custom password change form template {{ block.super }} {% endblock %}