fields: display page with single comment in summary (#56640)
gitea-wip/wcs/pipeline/head Build started... Details

This commit is contained in:
Lauréline Guérin 2021-09-10 16:15:41 +02:00
parent 060520e5bf
commit 8bef36e105
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 22 additions and 2 deletions

View File

@ -1460,7 +1460,7 @@ def test_form_summary_empty_pages(pub):
type='page',
condition={'type': 'python', 'value': 'form_var_toto == "foo"'},
),
fields.TitleField(id='6', label='title in second page', type='title'),
fields.TitleField(id='6', label='title in second page', type='title', display_locations=[]),
fields.StringField(id='3', label='string'),
fields.PageField(id='4', label='3rd page', type='page'),
fields.StringField(id='5', label='string'),
@ -1516,6 +1516,23 @@ def test_form_summary_empty_pages(pub):
assert '<h3>3rd page</h3>' in resp.text
assert '<h3>4th page</h3>' not in resp.text
formdef.fields[8].display_locations = ['summary']
formdef.store()
resp = app.get('/test/') # -> 1st page
resp.form['f1'] = 'foo'
resp = resp.form.submit('submit') # -> 2nd page
resp.form['f3'] = 'bar'
resp = resp.form.submit('submit') # -> 3rd page
resp.form['f5'] = 'baz'
resp = resp.form.submit('submit') # -> 4th page
resp = resp.form.submit('submit') # -> validation
resp = resp.form.submit('submit')
resp = resp.follow() # -> submit
assert '<h3>1st page</h3>' in resp.text
assert '<h3>2nd page</h3>' in resp.text
assert '<h3>3rd page</h3>' in resp.text
assert '<h3>4th page</h3>' in resp.text
def test_form_display_locations(pub):
formdef = create_formdef()

View File

@ -1343,7 +1343,10 @@ class FormData(StorableObject):
# ignore empty pages
fields_and_details = []
for page in pages:
if not any(bool('value' in x) for x in page['fields']):
if not any(
bool(x['field'].type in ('title', 'subtitle', 'comment') or 'value' in x)
for x in page['fields']
):
continue
fields_and_details.append(page)
fields_and_details.extend([x for x in page['fields']])