0001-forms-replaces-RadioSelect-by-Select-of-locked-attri.patch
src/authentic2/forms/profile.py | ||
---|---|---|
81 | 81 |
for av in models.AttributeValue.objects.with_owner(instance): |
82 | 82 |
if av.attribute.name in self.declared_fields: |
83 | 83 |
if av.verified: |
84 |
self.declared_fields[av.attribute.name].widget.attrs['readonly'] = 'readonly' |
|
84 |
widget = self.declared_fields[av.attribute.name].widget |
|
85 |
# RadioSelect are a special case, the HTML readonly attribute does not work on them |
|
86 |
# we must replace them by a combo box, see #32954. |
|
87 |
if isinstance(widget, forms.RadioSelect): |
|
88 |
new_widget = self.declared_fields[av.attribute.name].widget = forms.Select() |
|
89 |
try: |
|
90 |
new_widget._choices = widget._choices |
|
91 |
except AttributeError: |
|
92 |
# dj18 compatibility |
|
93 |
new_widget.choices = widget.choices |
|
94 |
widget = new_widget |
|
95 |
widget.attrs['readonly'] = 'readonly' |
|
85 | 96 |
initial[av.attribute.name] = av.to_python() |
86 | 97 |
super(BaseUserForm, self).__init__(*args, **kwargs) |
87 | 98 |
tests/test_profile.py | ||
---|---|---|
135 | 135 |
resp = app.get(reverse('profile_edit_with_scope', kwargs={'scope': 'address'}), |
136 | 136 |
status=200) |
137 | 137 |
assert get_fields(resp) == set(['city', 'zipcode', 'next_url']) |
138 | ||
139 | ||
140 |
def test_account_edit_locked_title(app, simple_user): |
|
141 |
Attribute.objects.create( |
|
142 |
name='title', label='title', |
|
143 |
kind='title', user_visible=True, user_editable=True) |
|
144 |
simple_user.attributes.title = 'Monsieur' |
|
145 | ||
146 |
utils.login(app, simple_user) |
|
147 |
url = reverse('profile_edit') |
|
148 |
response = app.get(url, status=200) |
|
149 |
assert len(response.pyquery('input[type="radio"][name="edit-profile-title"]')) == 2 |
|
150 |
assert len(response.pyquery('input[type="radio"][name="edit-profile-title"][readonly="true"]')) == 0 |
|
151 |
assert len(response.pyquery('select[name="edit-profile-title"]')) == 0 |
|
152 | ||
153 |
simple_user.verified_attributes.title = 'Monsieur' |
|
154 | ||
155 |
response = app.get(url, status=200) |
|
156 |
assert len(response.pyquery('input[type="radio"][name="edit-profile-title"][readonly=true]')) == 0 |
|
157 |
assert len(response.pyquery('select[name="edit-profile-title"]')) == 1 |
|
138 |
- |