From 462c464e2cf127e67404ee15818cf6131ed98d2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Sun, 28 Oct 2018 16:39:31 +0100 Subject: [PATCH] misc: don't repeat title identical to page name on summary page (#26732) --- tests/test_form_pages.py | 21 +++++++++++++++++++++ wcs/fields.py | 6 ++---- wcs/formdef.py | 8 ++++++-- wcs/forms/common.py | 2 +- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/tests/test_form_pages.py b/tests/test_form_pages.py index 838c95cf3..ae8557880 100644 --- a/tests/test_form_pages.py +++ b/tests/test_form_pages.py @@ -1058,6 +1058,27 @@ def test_form_multi_page_page_name_as_title(pub): assert 'Check values then click submit.' in next_page.body assert next_page.body.count('1st page') == 2 # in steps and in main body + # add a comment that will not be displayed and should therefore not be + # considered. + formdef.fields = [fields.PageField(id='0', label='1st page', type='page'), + fields.CommentField(id='5', label='bla bla bla', type='comment'), + fields.TitleField(id='4', label='1st page', type='title'), + fields.StringField(id='1', label='string'), + fields.PageField(id='2', label='2nd page', type='page'), + fields.StringField(id='3', label='string 2')] + formdef.store() + page = get_app(pub).get('/test/') + formdef.data_class().wipe() + page.forms[0]['f1'] = 'foo' + next_page = page.forms[0].submit('submit') + assert_current_page(next_page, '2nd page') + assert next_page.forms[0]['previous'] + next_page.forms[0]['f3'] = 'bar' + next_page = next_page.forms[0].submit('submit') + assert_current_page(next_page, 'Validating') + assert 'Check values then click submit.' in next_page.body + assert next_page.body.count('1st page') == 2 # in steps and in main body + def test_form_submit_with_user(pub, emails): create_user(pub) formdef = create_formdef() diff --git a/wcs/fields.py b/wcs/fields.py index d3f93ebd3..0ff4c0f6b 100644 --- a/wcs/fields.py +++ b/wcs/fields.py @@ -623,8 +623,7 @@ class CommentField(Field): form.widgets.append(widget) return widget - def add_to_view_form(self, *args): - pass + add_to_view_form = None def fill_admin_form(self, form): if self.label and (not self.label.startswith('<') and ( @@ -1689,8 +1688,7 @@ class PageField(Field): changed = True return changed - def add_to_view_form(self, *args): - pass + add_to_view_form = None register_field_class(PageField) diff --git a/wcs/formdef.py b/wcs/formdef.py index 83f3780e9..dc576c0cd 100644 --- a/wcs/formdef.py +++ b/wcs/formdef.py @@ -571,6 +571,7 @@ class FormDef(StorableObject): form.attrs['style'] = 'display: none;' if self.keywords: form.attrs['data-keywords'] = ' '.join(self.keywords_list) + current_page_fields = [] on_disabled_page = False on_page = False for i, field in enumerate(self.fields): @@ -597,17 +598,20 @@ class FormDef(StorableObject): form.widgets.append(HtmlWidget( htmltext('

%s

' % field.label))) on_page = field + current_page_fields = [] + continue if field.type == 'title' and on_page and ( - self.fields[i-1] is on_page and + not current_page_fields and on_page.label == field.label): # don't include first title of a page if that title has the # same text as the page. continue - if not field.is_visible(dict, self): + if field.add_to_view_form is None or not field.is_visible(dict, self): continue + current_page_fields.append(field) value = dict.get(field.id, '') field.add_to_view_form(form, value) diff --git a/wcs/forms/common.py b/wcs/forms/common.py index add8cf06c..0694c6748 100644 --- a/wcs/forms/common.py +++ b/wcs/forms/common.py @@ -362,7 +362,7 @@ class FormStatusPage(Directory, FormTemplateMixin): pages.append({'page': f, 'fields': current_page_fields}) continue - if f.type == 'title' and on_page and fields[i-1] is on_page and on_page.label == f.label: + if f.type == 'title' and on_page and not current_page_fields and on_page.label == f.label: # don't include first title of a page if that title has the # same text as the page. continue -- 2.19.1