Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

#17890: added support for extra_context in django.contrib.admin.site.password_change #64

Closed
wants to merge 1 commit into from

1 participant

Stephen Muss
Stephen Muss

Allows for extra_context to be passed in to the method password_change in django.contrib.admin.site

"python runtests.py --settings=test_sqlite" passes all tests.

Stephen Muss

Closing. Have submitted a new pull request at #499

Stephen Muss stephenmuss closed this November 05, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

May 19, 2012
Stephen Muss 17890: added support for extra_context in django.contrib.admin.site.p…
…assword_change
54ecaf4
This page is out of date. Refresh to see the latest.
5  django/contrib/admin/sites.py
@@ -249,7 +249,7 @@ def wrapper(*args, **kwargs):
249 249
     def urls(self):
250 250
         return self.get_urls(), self.app_name, self.name
251 251
 
252  
-    def password_change(self, request):
  252
+    def password_change(self, request, extra_context=None):
253 253
         """
254 254
         Handles the "change password" task -- both form display and validation.
255 255
         """
@@ -257,7 +257,8 @@ def password_change(self, request):
257 257
         url = reverse('admin:password_change_done', current_app=self.name)
258 258
         defaults = {
259 259
             'current_app': self.name,
260  
-            'post_change_redirect': url
  260
+            'post_change_redirect': url,
  261
+            'extra_context': extra_context
261 262
         }
262 263
         if self.password_change_template is not None:
263 264
             defaults['template_name'] = self.password_change_template
3  tests/regressiontests/admin_views/customadmin.py
@@ -24,6 +24,9 @@ class Admin2(admin.AdminSite):
24 24
     def index(self, request, extra_context=None):
25 25
         return super(Admin2, self).index(request, {'foo': '*bar*'})
26 26
 
  27
+    def password_change(self, request, extra_context={'EXTRA_CONTEXT': 'this is some extra context'}):
  28
+        return super(Admin2, self).password_change(request, extra_context)
  29
+
27 30
     def get_urls(self):
28 31
         return patterns('',
29 32
             (r'^my_view/$', self.admin_view(self.my_view)),
7  tests/regressiontests/admin_views/tests.py
@@ -763,6 +763,13 @@ def testCustomAdminSitePasswordChangeTemplate(self):
763 763
         self.assertTemplateUsed(request, 'custom_admin/password_change_form.html')
764 764
         self.assertTrue('Hello from a custom password change form template' in request.content)
765 765
 
  766
+    def testCustomAdminSitePasswordChangeWithExtraContext(self):
  767
+        "#17890: Test support for extra_context in password_change"
  768
+        request = self.client.get('/test_admin/admin2/password_change/')
  769
+        self.assertIsInstance(request, TemplateResponse)
  770
+        self.assertTemplateUsed(request, 'custom_admin/password_change_form.html')
  771
+        self.assertTrue('this is some extra context' in request.content)
  772
+
766 773
     def testCustomAdminSitePasswordChangeDoneTemplate(self):
767 774
         request = self.client.get('/test_admin/admin2/password_change/done/')
768 775
         self.assertIsInstance(request, TemplateResponse)
1  tests/templates/custom_admin/password_change_form.html
@@ -2,5 +2,6 @@
2 2
 
3 3
 {% block content %}
4 4
 Hello from a custom password change form template
  5
+{{ EXTRA_CONTEXT }}
5 6
 {{ block.super }}
6 7
 {% endblock %}
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.