File tree 5 files changed +15
-2
lines changed 5 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -281,7 +281,7 @@ def each_context(self):
281
281
'site_url' : self .site_url ,
282
282
}
283
283
284
- def password_change (self , request ):
284
+ def password_change (self , request , extra_context = None ):
285
285
"""
286
286
Handles the "change password" task -- both form display and validation.
287
287
"""
@@ -292,7 +292,7 @@ def password_change(self, request):
292
292
'current_app' : self .name ,
293
293
'password_change_form' : AdminPasswordChangeForm ,
294
294
'post_change_redirect' : url ,
295
- 'extra_context' : self .each_context (),
295
+ 'extra_context' : dict ( self .each_context (), ** ( extra_context or {}) ),
296
296
}
297
297
if self .password_change_template is not None :
298
298
defaults ['template_name' ] = self .password_change_template
Original file line number Diff line number Diff line change @@ -100,6 +100,9 @@ Minor features
100
100
<django.contrib.admin.ModelAdmin.show_full_result_count>` to control whether
101
101
or not the full count of objects should be displayed on a filtered admin page.
102
102
103
+ * The ``AdminSite.password_change()`` method now has an ``extra_context``
104
+ parameter.
105
+
103
106
:mod:`django.contrib.admindocs`
104
107
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
105
108
Original file line number Diff line number Diff line change @@ -33,6 +33,9 @@ def get_urls(self):
33
33
def my_view (self , request ):
34
34
return HttpResponse ("Django is a magical pony!" )
35
35
36
+ def password_change (self , request , extra_context = None ):
37
+ return super (Admin2 , self ).password_change (request , {'spam' : 'eggs' })
38
+
36
39
37
40
class UserLimitedAdmin (UserAdmin ):
38
41
# used for testing password change on a user not in queryset
Original file line number Diff line number Diff line change @@ -1012,6 +1012,12 @@ def test_custom_admin_site_password_change_template(self):
1012
1012
self .assertTemplateUsed (response , 'custom_admin/password_change_form.html' )
1013
1013
self .assertContains (response , 'Hello from a custom password change form template' )
1014
1014
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
+
1015
1021
def test_custom_admin_site_password_change_done_template (self ):
1016
1022
response = self .client .get ('/test_admin/admin2/password_change/done/' )
1017
1023
self .assertIsInstance (response , TemplateResponse )
Original file line number Diff line number Diff line change 1
1
{% extends "registration/password_change_form.html" %}
2
2
3
3
{% block content %}
4
+ {{ spam }}
4
5
Hello from a custom password change form template
5
6
{{ block.super }}
6
7
{% endblock %}
You can’t perform that action at this time.
0 commit comments