From 67a897c5d4d4d01a8400245816348faf4b6b086b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Wed, 19 Sep 2018 14:01:20 +0200 Subject: [PATCH] misc: use a django template to render form steps (#26562) --- tests/test_form_pages.py | 5 +++-- wcs/backoffice/submission.py | 1 + wcs/forms/root.py | 30 +++++++-------------------- wcs/templates/wcs/formdata_steps.html | 16 ++++++++++++++ 4 files changed, 27 insertions(+), 25 deletions(-) create mode 100644 wcs/templates/wcs/formdata_steps.html diff --git a/tests/test_form_pages.py b/tests/test_form_pages.py index 311320dd4..37bb1a16f 100644 --- a/tests/test_form_pages.py +++ b/tests/test_form_pages.py @@ -464,8 +464,9 @@ def test_form_items_submit(pub): assert data.data['0_display'] == 'Foo, Bar' def assert_current_page(resp, page_label): - assert re.findall('
  • .*?(.*?)
  • ', - resp.body)[0] == page_label + for li_tag in resp.html.findAll('li'): + if 'current' in li_tag.attrs['class']: + assert li_tag.find_all('span')[-1].text == page_label def test_form_multi_page(pub): for initial_condition in (None, 'True'): diff --git a/wcs/backoffice/submission.py b/wcs/backoffice/submission.py index 64fb6cfc8..6ee7affec 100644 --- a/wcs/backoffice/submission.py +++ b/wcs/backoffice/submission.py @@ -79,6 +79,7 @@ class FormFillPage(PublicFormFillPage): filling_templates = ['wcs/formdata_filling.html'] validation_templates = ['wcs/formdata_validation.html'] + steps_templates = ['wcs/formdata_steps.html'] def __init__(self, *args, **kwargs): super(FormFillPage, self).__init__(*args, **kwargs) diff --git a/wcs/forms/root.py b/wcs/forms/root.py index 513d21075..ef2ae94b9 100644 --- a/wcs/forms/root.py +++ b/wcs/forms/root.py @@ -177,6 +177,7 @@ class FormPage(Directory, FormTemplateMixin): do_not_call_in_templates = True filling_templates = ['wcs/front/formdata_filling.html', 'wcs/formdata_filling.html'] validation_templates = ['wcs/front/formdata_validation.html', 'wcs/formdata_validation.html'] + steps_templates = ['wcs/front/formdata_steps.html', 'wcs/formdata_steps.html'] def __init__(self, component): try: @@ -253,29 +254,12 @@ class FormPage(Directory, FormTemplateMixin): if self.has_confirmation_page() and not self.edit_mode: page_labels.append(_('Validating')) - r = TemplateIO(html=True) - r += htmltext('
      ') % len(page_labels) - - for i, page_label in enumerate(page_labels): - classes = [] - index = i + 1 - if index == 1: - classes.append('first') - if index == len(page_labels): - classes.append('last') - if index == current_position: - classes.append('current') - elif index < current_position: - classes.append('step-before') - elif index > current_position: - classes.append('step-after') - r += htmltext('
    1. ') % ' '.join(classes) - r += htmltext('%d %s') % ( - index, page_label) - r += htmltext('
    2. ') - - r += htmltext('
    ') - return r.getvalue() + return template.render( + list(self.get_formdef_template_variants(self.steps_templates)), + { + 'page_labels': page_labels, + 'current_page_no': current_position, + }) def page(self, page, page_change=True, page_error_messages=None): displayed_fields = [] diff --git a/wcs/templates/wcs/formdata_steps.html b/wcs/templates/wcs/formdata_steps.html new file mode 100644 index 000000000..0a6ff6b16 --- /dev/null +++ b/wcs/templates/wcs/formdata_steps.html @@ -0,0 +1,16 @@ +
    +
      +{% for page_label in page_labels %} +{% spaceless %} +
    1. + {{ forloop.counter }} + {{ page_label }} +
    2. +{% endspaceless %} +{% endfor %} +
    +
    -- 2.19.0