Ticket #31472: fix.patch
File fix.patch, 2.6 KB (added by , 5 years ago) |
---|
-
django/contrib/auth/admin.py
diff --git a/django/contrib/auth/admin.py b/django/contrib/auth/admin.py index 6709e63..75ebc9b 100644
a b class UserAdmin(admin.ModelAdmin): 65 65 filter_horizontal = ('groups', 'user_permissions',) 66 66 67 67 def get_fieldsets(self, request, obj=None): 68 if not obj:68 if obj is None: 69 69 return self.add_fieldsets 70 70 return super().get_fieldsets(request, obj) 71 71 -
tests/modeladmin/tests.py
diff --git a/tests/modeladmin/tests.py b/tests/modeladmin/tests.py index 6934bf2..ceb8123 100644
a b from django.contrib.admin.widgets import ( 11 11 AdminDateWidget, AdminRadioSelect, AutocompleteSelect, 12 12 AutocompleteSelectMultiple, 13 13 ) 14 from django.contrib.auth.admin import UserAdmin 14 15 from django.contrib.auth.models import User 15 16 from django.db import models 16 17 from django.forms.widgets import Select … … class ModelAdminTests(TestCase): 67 68 self.assertEqual(ma.get_fieldsets(request), [(None, {'fields': ['name', 'bio', 'sign_date']})]) 68 69 self.assertEqual(ma.get_fieldsets(request, self.band), [(None, {'fields': ['name', 'bio', 'sign_date']})]) 69 70 71 def test_default_fieldsets_useradmin(self): 72 # Here's the default case. There are no custom form_add/form_change methods, 73 # no fields argument, and no fieldsets argument. 74 class CustomUser(User): 75 is_deleted = models.BooleanField(default=False) 76 77 def __bool__(self): 78 return not self.is_deleted 79 80 ua = UserAdmin(CustomUser, self.site) 81 user = CustomUser() 82 83 add_fieldsets = ((None, { 84 'classes': ('wide',), 'fields': ('username', 'password1', 'password2') 85 }),) 86 change_fieldsets = ( 87 (None, {'fields': ('username', 'password')}), 88 ('Personal info', {'fields': ('first_name', 'last_name', 'email')}), 89 ('Permissions', {'fields': 90 ('is_active', 'is_staff', 'is_superuser', 'groups', 'user_permissions') 91 }), 92 ('Important dates', {'fields': ('last_login', 'date_joined')}), 93 ) 94 95 self.assertEqual(ua.get_fieldsets(request), add_fieldsets) 96 self.assertEqual(ua.get_fieldsets(request, user), change_fieldsets) 97 98 user.is_deleted = True 99 self.assertEqual(ua.get_fieldsets(request, user), change_fieldsets) 100 70 101 def test_get_fieldsets(self): 71 102 # get_fieldsets() is called when figuring out form fields (#18681). 72 103 class BandAdmin(ModelAdmin):