mirror of https://github.com/django/django.git
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
This commit is contained in:
parent
a3e7ee7c40
commit
0e26f58dae
|
@ -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 @@ class UserAdmin(admin.ModelAdmin):
|
|||
'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)
|
||||
|
|
|
@ -18,7 +18,7 @@ from django.utils import formats
|
|||
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
|
||||
from django.utils import unittest
|
||||
|
||||
# local test models
|
||||
|
@ -1538,7 +1538,7 @@ class AdminActionsTest(TestCase):
|
|||
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")
|
||||
|
||||
|
@ -2164,7 +2164,19 @@ class UserAdminTest(TestCase):
|
|||
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',
|
||||
|
@ -2174,8 +2186,8 @@ class UserAdminTest(TestCase):
|
|||
})
|
||||
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/', {
|
||||
|
@ -2183,21 +2195,22 @@ class UserAdminTest(TestCase):
|
|||
'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',
|
||||
|
@ -2207,8 +2220,8 @@ class UserAdminTest(TestCase):
|
|||
})
|
||||
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:
|
||||
import docutils
|
||||
|
|
Loading…
Reference in New Issue