diff --git a/app/all_questions/metadata_utils.py b/app/all_questions/metadata_utils.py index 3efccf06..2c6bbd75 100644 --- a/app/all_questions/metadata_utils.py +++ b/app/all_questions/metadata_utils.py @@ -376,7 +376,7 @@ def build_components_from_page( if "condition" in next_config and next_config["path"] != "/summary": condition_name = next_config["condition"] condition_config = next(fc for fc in form_conditions if fc["name"] == condition_name) - destination = index_of_printed_headers[next_config["path"]]["heading_number"] + destination = index_of_printed_headers[next_config["path"]]["title"] text_with_coordinators = "" for condition in [ cc for cc in condition_config["value"]["conditions"] if cc["field"]["name"] == c["name"] diff --git a/app/blueprints/application/routes.py b/app/blueprints/application/routes.py index 9d0edea1..0aa5cfa8 100644 --- a/app/blueprints/application/routes.py +++ b/app/blueprints/application/routes.py @@ -32,7 +32,7 @@ from app.db.queries.clone import clone_single_form from app.db.queries.fund import get_all_funds, get_fund_by_id from app.db.queries.round import get_round_by_id -from app.export_config.generate_all_questions import print_html +from app.export_config.generate_all_questions import generate_html from app.export_config.generate_assessment_config import ( generate_assessment_config_for_round, ) @@ -121,7 +121,7 @@ def view_all_questions(round_id): section_data, lang="en", ) - html = print_html(print_data) + html = generate_html(print_data) return render_template( "view_questions.html", round=round, @@ -263,7 +263,7 @@ def view_form_questions(round_id, section_id, form_id): section_data, lang="en", ) - html = print_html(print_data, True) + html = generate_html(print_data, True) return render_template( "view_questions.html", round=round, fund=fund, question_html=html, title=form.name_in_apply_json["en"] ) diff --git a/app/blueprints/template/routes.py b/app/blueprints/template/routes.py index fd382082..d5fabeea 100644 --- a/app/blueprints/template/routes.py +++ b/app/blueprints/template/routes.py @@ -13,7 +13,7 @@ get_form_by_template_name, update_form, ) -from app.export_config.generate_all_questions import print_html +from app.export_config.generate_all_questions import generate_html from app.export_config.generate_form import build_form_json from app.export_config.helpers import human_to_kebab_case from app.shared.helpers import flash_message @@ -96,7 +96,7 @@ def template_questions(form_id): section_data, lang="en", ) - html = print_html(print_data, False, False, False) + html = generate_html(print_data, False, False) return render_template("view_template_questions.html", question_html=html, form=form) diff --git a/app/export_config/generate_all_questions.py b/app/export_config/generate_all_questions.py index 279b397f..f1fadff5 100644 --- a/app/export_config/generate_all_questions.py +++ b/app/export_config/generate_all_questions.py @@ -1,9 +1,8 @@ -from airium import Airium # noqa: E402 +from airium import Airium -# Initialise Airium html printer -air = Airium() - -# Define start and end html +# -------------------------- +# Boilerplate HTML Templates +# -------------------------- BOILERPLATE_START = """ {% extends "apply/base.html" %} {%- from 'govuk_frontend_jinja/components/inset-text/macro.html' import govukInsetText -%} @@ -14,8 +13,7 @@ {% block content %}
- {% trans %}{{fund_title}}{% endtrans %} {% trans %}{{round_title}}{% endtrans %} - + {% trans %}{{fund_title}}{% endtrans %} {% trans %}{{round_title}}{% endtrans %}

{{pageHeading}}

""" @@ -26,14 +24,21 @@ """ -def print_html_toc(air: Airium, sections: dict): - """Prints a table of contents for the supplied sections to the supplied `Airium` instance - - Args: - air (Airium): Instance to write html to - sections (dict): Sections for this TOC +# -------------------------- +# Table of Contents Section +# -------------------------- +def generate_table_of_contents(air, sections): """ - with air.h2(klass="govuk-heading-m "): + Generates a table of contents from the given sections. + + Example Output: +

Table of contents

+
    +
  1. Section 1
  2. +
  3. Section 2
  4. +
+ """ + with air.h2(klass="govuk-heading-m"): air("Table of contents") with air.ol(klass="govuk-list govuk-list--number"): for anchor, details in sections.items(): @@ -42,92 +47,79 @@ def print_html_toc(air: Airium, sections: dict): air(details["title_text"]) -def print_components(air: Airium, components: list, show_field_types: bool = False): - """Prints the components within a page - - Args: - air (Airium): Instance to print html - components (list): List of components to print +# -------------------------- +# Component Rendering Section +# -------------------------- +def render_components(air, components, show_field_types=False): """ - for c in components: - # Print the title + Renders components within a page. + + Example Output: +
+

Component Title [Type]

+
    +
  • Bullet 1
  • +
  • Bullet 2
  • +
+

Some additional text.

+
+ """ + for component in components: with air.div(klass="govuk-body all-questions-component"): - if not c["hide_title"] and c["title"] is not None: + title = component.get("title") + if not component.get("hide_title") and title: with air.p(klass="govuk-body"): - air(f"{c['title']}") + air(title) if show_field_types: - air(f" [{c['type']}]") + air(f" [{component['type']}]") - for t in c["text"]: - # Print lists as