Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Corrected change in behavior regarding the page shown after the 'Save…

…' button is pressed when adding a user through the admin.

It had been introduced in trunk (r13503) and between 1.2.1 and 1.2.2 (r13504). The original fix intended to correct a similar problem introduced between 1.1 and 1.2 (r12218) this time in the 'Save and add another' button.
We have now tests for the three buttons present in the Add User admin form to avoid future regressions.
Thanks to Juan Pedro Fisanotti and Cesar H. Roldan for their work.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14628 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 0e26f58dae5b0bace6dcadbad2def400c93cdf14 1 parent a3e7ee7
Ramiro Morales authored November 19, 2010
12  django/contrib/auth/admin.py
... ...
@@ -1,4 +1,3 @@
1  
-from django import template
2 1
 from django.db import transaction
3 2
 from django.conf import settings
4 3
 from django.contrib import admin
@@ -137,6 +136,17 @@ def user_change_password(self, request, id):
137 136
             'root_path': self.admin_site.root_path,
138 137
         }, context_instance=RequestContext(request))
139 138
 
  139
+    def response_add(self, request, obj, post_url_continue='../%s/'):
  140
+        """
  141
+        Determines the HttpResponse for the add_view stage. It mostly defers to
  142
+        its superclass implementation but is customized because the User model
  143
+        has a slightly different workflow.
  144
+        """
  145
+        if '_addanother' not in request.POST:
  146
+            # The 'Save' button should act like the 'Save and continue
  147
+            # editing' button
  148
+            request.POST['_continue'] = 1
  149
+        return super(UserAdmin, self).response_add(request, obj, post_url_continue)
140 150
 
141 151
 admin.site.register(Group, GroupAdmin)
142 152
 admin.site.register(User, UserAdmin)
37  tests/regressiontests/admin_views/tests.py
@@ -18,7 +18,7 @@
18 18
 from django.utils.cache import get_max_age
19 19
 from django.utils.encoding import iri_to_uri
20 20
 from django.utils.html import escape
21  
-from django.utils.translation import get_date_formats, activate, deactivate
  21
+from django.utils.translation import activate, deactivate
22 22
 from django.utils import unittest
23 23
 
24 24
 # local test models
@@ -1538,7 +1538,7 @@ def test_model_without_action_still_has_jquery(self):
1538 1538
     def test_action_column_class(self):
1539 1539
         "Tests that the checkbox column class is present in the response"
1540 1540
         response = self.client.get('/test_admin/admin/admin_views/subscriber/')
1541  
-        self.assertNotEquals(response.context["action_form"], None)
  1541
+        self.assertNotEqual(response.context["action_form"], None)
1542 1542
         self.assert_('action-checkbox-column' in response.content,
1543 1543
             "Expected an action-checkbox-column in response")
1544 1544
 
@@ -2164,7 +2164,19 @@ def setUp(self):
2164 2164
     def tearDown(self):
2165 2165
         self.client.logout()
2166 2166
 
2167  
-    def test_user_creation(self):
  2167
+    def test_save_button(self):
  2168
+        user_count = User.objects.count()
  2169
+        response = self.client.post('/test_admin/admin/auth/user/add/', {
  2170
+            'username': 'newuser',
  2171
+            'password1': 'newpassword',
  2172
+            'password2': 'newpassword',
  2173
+        })
  2174
+        new_user = User.objects.order_by('-id')[0]
  2175
+        self.assertRedirects(response, '/test_admin/admin/auth/user/%s/' % new_user.pk)
  2176
+        self.assertEqual(User.objects.count(), user_count + 1)
  2177
+        self.assertNotEqual(new_user.password, UNUSABLE_PASSWORD)
  2178
+
  2179
+    def test_save_continue_editing_button(self):
2168 2180
         user_count = User.objects.count()
2169 2181
         response = self.client.post('/test_admin/admin/auth/user/add/', {
2170 2182
             'username': 'newuser',
@@ -2174,8 +2186,8 @@ def test_user_creation(self):
2174 2186
         })
2175 2187
         new_user = User.objects.order_by('-id')[0]
2176 2188
         self.assertRedirects(response, '/test_admin/admin/auth/user/%s/' % new_user.pk)
2177  
-        self.assertEquals(User.objects.count(), user_count + 1)
2178  
-        self.assertNotEquals(new_user.password, UNUSABLE_PASSWORD)
  2189
+        self.assertEqual(User.objects.count(), user_count + 1)
  2190
+        self.assertNotEqual(new_user.password, UNUSABLE_PASSWORD)
2179 2191
 
2180 2192
     def test_password_mismatch(self):
2181 2193
         response = self.client.post('/test_admin/admin/auth/user/add/', {
@@ -2183,21 +2195,22 @@ def test_password_mismatch(self):
2183 2195
             'password1': 'newpassword',
2184 2196
             'password2': 'mismatch',
2185 2197
         })
2186  
-        self.assertEquals(response.status_code, 200)
  2198
+        self.assertEqual(response.status_code, 200)
2187 2199
         adminform = response.context['adminform']
2188  
-        self.assert_('password' not in adminform.form.errors)
2189  
-        self.assertEquals(adminform.form.errors['password2'],
  2200
+        self.assertTrue('password' not in adminform.form.errors)
  2201
+        self.assertEqual(adminform.form.errors['password2'],
2190 2202
                           [u"The two password fields didn't match."])
2191 2203
 
2192 2204
     def test_user_fk_popup(self):
2193 2205
         response = self.client.get('/test_admin/admin/admin_views/album/add/')
2194  
-        self.failUnlessEqual(response.status_code, 200)
  2206
+        self.assertEqual(response.status_code, 200)
2195 2207
         self.assertContains(response, '/test_admin/admin/auth/user/add')
2196 2208
         self.assertContains(response, 'class="add-another" id="add_id_owner" onclick="return showAddAnotherPopup(this);"')
2197 2209
         response = self.client.get('/test_admin/admin/auth/user/add/?_popup=1')
2198 2210
         self.assertNotContains(response, 'name="_continue"')
  2211
+        self.assertNotContains(response, 'name="_addanother"')
2199 2212
 
2200  
-    def test_user_add_another(self):
  2213
+    def test_save_add_another_button(self):
2201 2214
         user_count = User.objects.count()
2202 2215
         response = self.client.post('/test_admin/admin/auth/user/add/', {
2203 2216
             'username': 'newuser',
@@ -2207,8 +2220,8 @@ def test_user_add_another(self):
2207 2220
         })
2208 2221
         new_user = User.objects.order_by('-id')[0]
2209 2222
         self.assertRedirects(response, '/test_admin/admin/auth/user/add/')
2210  
-        self.assertEquals(User.objects.count(), user_count + 1)
2211  
-        self.assertNotEquals(new_user.password, UNUSABLE_PASSWORD)
  2223
+        self.assertEqual(User.objects.count(), user_count + 1)
  2224
+        self.assertNotEqual(new_user.password, UNUSABLE_PASSWORD)
2212 2225
 
2213 2226
 try:
2214 2227
     import docutils

0 notes on commit 0e26f58

Please sign in to comment.
Something went wrong with that request. Please try again.