Skip to content

Commit c8dcded

Browse files
berkerpeksagtimgraham
authored andcommitted
Fixed django#17890 -- Added an extra_context parameter to AdminSite.password_change().
1 parent 3131e9c commit c8dcded

File tree

5 files changed

+15
-2
lines changed

5 files changed

+15
-2
lines changed

django/contrib/admin/sites.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def each_context(self):
281281
'site_url': self.site_url,
282282
}
283283

284-
def password_change(self, request):
284+
def password_change(self, request, extra_context=None):
285285
"""
286286
Handles the "change password" task -- both form display and validation.
287287
"""
@@ -292,7 +292,7 @@ def password_change(self, request):
292292
'current_app': self.name,
293293
'password_change_form': AdminPasswordChangeForm,
294294
'post_change_redirect': url,
295-
'extra_context': self.each_context(),
295+
'extra_context': dict(self.each_context(), **(extra_context or {})),
296296
}
297297
if self.password_change_template is not None:
298298
defaults['template_name'] = self.password_change_template

docs/releases/1.8.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ Minor features
100100
<django.contrib.admin.ModelAdmin.show_full_result_count>` to control whether
101101
or not the full count of objects should be displayed on a filtered admin page.
102102

103+
* The ``AdminSite.password_change()`` method now has an ``extra_context``
104+
parameter.
105+
103106
:mod:`django.contrib.admindocs`
104107
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
105108

tests/admin_views/customadmin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ def get_urls(self):
3333
def my_view(self, request):
3434
return HttpResponse("Django is a magical pony!")
3535

36+
def password_change(self, request, extra_context=None):
37+
return super(Admin2, self).password_change(request, {'spam': 'eggs'})
38+
3639

3740
class UserLimitedAdmin(UserAdmin):
3841
# used for testing password change on a user not in queryset

tests/admin_views/tests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,12 @@ def test_custom_admin_site_password_change_template(self):
10121012
self.assertTemplateUsed(response, 'custom_admin/password_change_form.html')
10131013
self.assertContains(response, 'Hello from a custom password change form template')
10141014

1015+
def test_custom_admin_site_password_change_with_extra_context(self):
1016+
response = self.client.get('/test_admin/admin2/password_change/')
1017+
self.assertIsInstance(response, TemplateResponse)
1018+
self.assertTemplateUsed(response, 'custom_admin/password_change_form.html')
1019+
self.assertContains(response, 'eggs')
1020+
10151021
def test_custom_admin_site_password_change_done_template(self):
10161022
response = self.client.get('/test_admin/admin2/password_change/done/')
10171023
self.assertIsInstance(response, TemplateResponse)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{% extends "registration/password_change_form.html" %}
22

33
{% block content %}
4+
{{ spam }}
45
Hello from a custom password change form template
56
{{ block.super }}
67
{% endblock %}

0 commit comments

Comments
 (0)