Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.2.X] Corrected change in behavior regarding the page shown after t…

…he '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.

Backport of [14628] from trunk

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14629 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 237e9557d77b40348eb387e608cfe4565c988e5e 1 parent da163cc
Ramiro Morales ramiro authored
12 django/contrib/auth/admin.py
View
@@ -1,4 +1,3 @@
-from django import template
from django.db import transaction
from django.conf import settings
from django.contrib import admin
@@ -137,6 +136,17 @@ def user_change_password(self, request, id):
'root_path': self.admin_site.root_path,
}, context_instance=RequestContext(request))
+ def response_add(self, request, obj, post_url_continue='../%s/'):
+ """
+ Determines the HttpResponse for the add_view stage. It mostly defers to
+ its superclass implementation but is customized because the User model
+ has a slightly different workflow.
+ """
+ if '_addanother' not in request.POST:
+ # The 'Save' button should act like the 'Save and continue
+ # editing' button
+ request.POST['_continue'] = 1
+ return super(UserAdmin, self).response_add(request, obj, post_url_continue)
admin.site.register(Group, GroupAdmin)
admin.site.register(User, UserAdmin)
37 tests/regressiontests/admin_views/tests.py
View
@@ -17,7 +17,7 @@
from django.utils.cache import get_max_age
from django.utils.encoding import iri_to_uri
from django.utils.html import escape
-from django.utils.translation import get_date_formats, activate, deactivate
+from django.utils.translation import activate, deactivate
import django.template.context
# local test models
@@ -1515,7 +1515,7 @@ def test_model_without_action_still_has_jquery(self):
def test_action_column_class(self):
"Tests that the checkbox column class is present in the response"
response = self.client.get('/test_admin/admin/admin_views/subscriber/')
- self.assertNotEquals(response.context["action_form"], None)
+ self.assertNotEqual(response.context["action_form"], None)
self.assert_('action-checkbox-column' in response.content,
"Expected an action-checkbox-column in response")
@@ -2141,7 +2141,19 @@ def setUp(self):
def tearDown(self):
self.client.logout()
- def test_user_creation(self):
+ def test_save_button(self):
+ user_count = User.objects.count()
+ response = self.client.post('/test_admin/admin/auth/user/add/', {
+ 'username': 'newuser',
+ 'password1': 'newpassword',
+ 'password2': 'newpassword',
+ })
+ new_user = User.objects.order_by('-id')[0]
+ self.assertRedirects(response, '/test_admin/admin/auth/user/%s/' % new_user.pk)
+ self.assertEqual(User.objects.count(), user_count + 1)
+ self.assertNotEqual(new_user.password, UNUSABLE_PASSWORD)
+
+ def test_save_continue_editing_button(self):
user_count = User.objects.count()
response = self.client.post('/test_admin/admin/auth/user/add/', {
'username': 'newuser',
@@ -2151,8 +2163,8 @@ def test_user_creation(self):
})
new_user = User.objects.order_by('-id')[0]
self.assertRedirects(response, '/test_admin/admin/auth/user/%s/' % new_user.pk)
- self.assertEquals(User.objects.count(), user_count + 1)
- self.assertNotEquals(new_user.password, UNUSABLE_PASSWORD)
+ self.assertEqual(User.objects.count(), user_count + 1)
+ self.assertNotEqual(new_user.password, UNUSABLE_PASSWORD)
def test_password_mismatch(self):
response = self.client.post('/test_admin/admin/auth/user/add/', {
@@ -2160,21 +2172,22 @@ def test_password_mismatch(self):
'password1': 'newpassword',
'password2': 'mismatch',
})
- self.assertEquals(response.status_code, 200)
+ self.assertEqual(response.status_code, 200)
adminform = response.context['adminform']
- self.assert_('password' not in adminform.form.errors)
- self.assertEquals(adminform.form.errors['password2'],
+ self.assertTrue('password' not in adminform.form.errors)
+ self.assertEqual(adminform.form.errors['password2'],
[u"The two password fields didn't match."])
def test_user_fk_popup(self):
response = self.client.get('/test_admin/admin/admin_views/album/add/')
- self.failUnlessEqual(response.status_code, 200)
+ self.assertEqual(response.status_code, 200)
self.assertContains(response, '/test_admin/admin/auth/user/add')
self.assertContains(response, 'class="add-another" id="add_id_owner" onclick="return showAddAnotherPopup(this);"')
response = self.client.get('/test_admin/admin/auth/user/add/?_popup=1')
self.assertNotContains(response, 'name="_continue"')
+ self.assertNotContains(response, 'name="_addanother"')
- def test_user_add_another(self):
+ def test_save_add_another_button(self):
user_count = User.objects.count()
response = self.client.post('/test_admin/admin/auth/user/add/', {
'username': 'newuser',
@@ -2184,8 +2197,8 @@ def test_user_add_another(self):
})
new_user = User.objects.order_by('-id')[0]
self.assertRedirects(response, '/test_admin/admin/auth/user/add/')
- self.assertEquals(User.objects.count(), user_count + 1)
- self.assertNotEquals(new_user.password, UNUSABLE_PASSWORD)
+ self.assertEqual(User.objects.count(), user_count + 1)
+ self.assertNotEqual(new_user.password, UNUSABLE_PASSWORD)
try:
# If docutils isn't installed, skip the AdminDocs tests.
Please sign in to comment.
Something went wrong with that request. Please try again.