Author: ramiro Date: 2010-11-19 17:04:48 -0600 (Fri, 19 Nov 2010) New Revision: 14629
Modified: django/branches/releases/1.2.X/django/contrib/auth/admin.py django/branches/releases/1.2.X/tests/regressiontests/admin_views/tests.py Log: [1.2.X] 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. Backport of [14628] from trunk Modified: django/branches/releases/1.2.X/django/contrib/auth/admin.py =================================================================== --- django/branches/releases/1.2.X/django/contrib/auth/admin.py 2010-11-19 22:45:51 UTC (rev 14628) +++ django/branches/releases/1.2.X/django/contrib/auth/admin.py 2010-11-19 23:04:48 UTC (rev 14629) @@ -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 @@ '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) Modified: django/branches/releases/1.2.X/tests/regressiontests/admin_views/tests.py =================================================================== --- django/branches/releases/1.2.X/tests/regressiontests/admin_views/tests.py 2010-11-19 22:45:51 UTC (rev 14628) +++ django/branches/releases/1.2.X/tests/regressiontests/admin_views/tests.py 2010-11-19 23:04:48 UTC (rev 14629) @@ -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_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,18 +2141,30 @@ 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', + 'password1': 'newpassword', + 'password2': 'newpassword', '_continue': '1', }) 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 @@ '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 @@ }) 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. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-upda...@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.