From 51d05ed84df4c2c6783ded370d801980cbf280e2 Mon Sep 17 00:00:00 2001 From: Serghei Mihai Date: Fri, 29 May 2015 11:51:57 +0200 Subject: [PATCH] fix displaying custom user attributes in forms (#7386) --- src/authentic2/forms.py | 2 +- src/authentic2/tests.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/authentic2/forms.py b/src/authentic2/forms.py index 44032c2..216ec77 100644 --- a/src/authentic2/forms.py +++ b/src/authentic2/forms.py @@ -93,7 +93,7 @@ def modelform_factory(model, **kwargs): form = BaseUserForm attributes = models.Attribute.objects.all() for attribute in attributes: - if fields and attribute.name not in fields: + if attribute.name not in fields: continue d[attribute.name] = attribute.get_form_field() for field in app_settings.A2_REQUIRED_FIELDS: diff --git a/src/authentic2/tests.py b/src/authentic2/tests.py index 35fd574..997a4d0 100644 --- a/src/authentic2/tests.py +++ b/src/authentic2/tests.py @@ -501,6 +501,29 @@ class UserProfileTests(TestCase): self.assertEqual(form['custom'].value(), 'random data') self.assertEqual(form['national_number'].value(), 'xx20153566342yy') + def test_noneditable_profile_attributes(self): + """ + tests if user non editable attributes do not appear in profile form + """ + + models.Attribute.objects.create( + label=u'custom', + name='custom', + required=False, + user_editable=False, + kind='string') + models.Attribute.objects.create( + label=u'ID', + name='national_number', + user_editable=False, + user_visible=False, + kind='string') + + self.assertTrue(self.client.login(username='testbot', password='secret')) + response = self.client.get(reverse('profile_edit')) + form = get_response_form(response) + self.assertEqual(set(form.fields), set()) + class CacheTests(TestCase): urls = 'authentic2.cache_tests_urls' -- 2.1.4