0001-admin-warning-on-only_allow_one-field-56788.patch
tests/admin_pages/test_form.py | ||
---|---|---|
150 | 150 | |
151 | 151 |
def test_forms_edit_limit_one_form(pub, formdef): |
152 | 152 |
create_superuser(pub) |
153 |
create_role(pub) |
|
153 |
role = create_role(pub)
|
|
154 | 154 | |
155 | 155 |
app = login(get_app(pub)) |
156 | 156 |
resp = app.get('/backoffice/forms/1/') |
157 | 157 | |
158 | 158 |
# Limit to one form |
159 |
assert formdef.roles is None |
|
159 | 160 |
assert_option_display(resp, 'Limit to one form', 'Disabled') |
160 | 161 |
resp = resp.click('Limit to one form') |
162 |
assert 'Warning: this option concerns logged in users only.' in resp |
|
161 | 163 |
assert resp.forms[0]['only_allow_one'].checked is False |
162 | 164 |
resp.forms[0]['only_allow_one'].checked = True |
163 | 165 |
resp = resp.forms[0].submit() |
... | ... | |
166 | 168 |
assert_option_display(resp, 'Limit to one form', 'Enabled') |
167 | 169 |
assert FormDef.get(1).only_allow_one is True |
168 | 170 | |
171 |
formdef.roles = ['logged-users'] |
|
172 |
formdef.store() |
|
173 |
resp = app.get('/backoffice/forms/1/options/only_allow_one') |
|
174 |
assert 'Warning: this option concerns logged in users only.' not in resp |
|
175 | ||
176 |
formdef.roles = [str(role.id)] |
|
177 |
formdef.store() |
|
178 |
resp = app.get('/backoffice/forms/1/options/only_allow_one') |
|
179 |
assert 'Warning: this option concerns logged in users only.' not in resp |
|
180 | ||
181 |
formdef.always_advertise = True |
|
182 |
formdef.store() |
|
183 |
resp = app.get('/backoffice/forms/1/options/only_allow_one') |
|
184 |
assert 'Warning: this option concerns logged in users only.' in resp |
|
185 | ||
169 | 186 | |
170 | 187 |
def test_forms_edit_management(pub, formdef): |
171 | 188 |
create_superuser(pub) |
wcs/admin/forms.py | ||
---|---|---|
234 | 234 | |
235 | 235 |
def only_allow_one(self): |
236 | 236 |
form = Form(enctype='multipart/form-data') |
237 |
hint = None |
|
238 |
if not self.formdef.roles or self.formdef.always_advertise: |
|
239 |
hint = _('Warning: this option concerns logged in users only.') |
|
237 | 240 |
form.add( |
238 | 241 |
CheckboxWidget, |
239 | 242 |
'only_allow_one', |
240 | 243 |
title=_('Only allow one form per user'), |
241 | 244 |
value=self.formdef.only_allow_one, |
245 |
hint=hint, |
|
242 | 246 |
) |
243 | 247 |
return self.handle(form, _('Limit to one form')) |
244 | 248 | |
245 |
- |