summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Plant <L.Plant.98@cantab.net>2010-09-09 23:43:01 +0000
committerLuke Plant <L.Plant.98@cantab.net>2010-09-09 23:43:01 +0000
commit6ea90256d767bb79649df83ec2f5b0e265d6871b (patch)
treeb90204c26c685905c0cbd91d3cb651252fa52216
parent5357000bc3fc0e22c6708fc2bd11e3e4e5abecef (diff)
[1.2.X] Fixed #14242 - UserChangeForm subclasses without 'user_permissions' field causes KeyError
This was a regression introduced by [13684] Thanks to adammckerlie@gmail.com for report. Backport of [13702] from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@13704 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/contrib/auth/forms.py4
-rw-r--r--django/contrib/auth/tests/forms.py16
2 files changed, 19 insertions, 1 deletions
diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py
index 992a0ff44d..d20c472495 100644
--- a/django/contrib/auth/forms.py
+++ b/django/contrib/auth/forms.py
@@ -54,7 +54,9 @@ class UserChangeForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(UserChangeForm, self).__init__(*args, **kwargs)
- self.fields['user_permissions'].queryset = self.fields['user_permissions'].queryset.select_related('content_type')
+ f = self.fields.get('user_permissions', None)
+ if f is not None:
+ f.queryset = f.queryset.select_related('content_type')
class AuthenticationForm(forms.Form):
"""
diff --git a/django/contrib/auth/tests/forms.py b/django/contrib/auth/tests/forms.py
index 355b9eaf6e..5aa49e09c3 100644
--- a/django/contrib/auth/tests/forms.py
+++ b/django/contrib/auth/tests/forms.py
@@ -199,6 +199,22 @@ class UserChangeFormTest(TestCase):
self.assertEqual(form['username'].errors,
[u'This value may contain only letters, numbers and @/./+/-/_ characters.'])
+ def test_bug_14242(self):
+ # A regression test, introduce by adding an optimization for the
+ # UserChangeForm.
+
+ class MyUserForm(UserChangeForm):
+ def __init__(self, *args, **kwargs):
+ super(MyUserForm, self).__init__(*args, **kwargs)
+ self.fields['groups'].help_text = 'These groups give users different permissions'
+
+ class Meta(UserChangeForm.Meta):
+ fields = ('groups',)
+
+ # Just check we can create it
+ form = MyUserForm({})
+
+
class PasswordResetFormTest(TestCase):
fixtures = ['authtestdata.json']