Skip to content

Commit

Permalink
FAB - Import structured application template into the FAB tool (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam-W1 authored Aug 23, 2024
1 parent 00021fa commit 15f07ec
Show file tree
Hide file tree
Showing 42 changed files with 2,812 additions and 767 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,6 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# Script output directory
app/export_config/output/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Contained in [db_tasks.py](./tasks/db_tasks.py)
## Configuration Export Tasks
Contained in [export_tasks.py](./tasks/export_tasks.py)

The configuration output is generated by the [config_generator](./app/config_generator/README.md) module. This module contains functions to generate fund and round configuration, form JSONs, and HTML representations for a given funding round.
The configuration output is generated by the [config_generator](./app/export_config/README.md) module. This module contains functions to generate fund and round configuration, form JSONs, and HTML representations for a given funding round.

## Database
### Schema
Expand Down
6 changes: 5 additions & 1 deletion app/all_questions/metadata_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,11 @@ def determine_title_and_text_for_component(
extract_from_html(soup, text)
update_wording_for_multi_input_fields(text)

if component["type"].casefold() in FIELD_TYPES_WITH_MAX_WORDS and not is_child:
if (
component["type"].casefold() in FIELD_TYPES_WITH_MAX_WORDS
and not is_child
and "maxWords" in component["options"]
):
text.append(f"(Max {component['options']['maxWords']} words)")

if "list" in component:
Expand Down
42 changes: 40 additions & 2 deletions app/blueprints/fund_builder/routes.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import json
import os
import shutil
from datetime import datetime
from random import randint

import requests
from flask import Blueprint
from flask import Response
from flask import after_this_request
from flask import flash
from flask import redirect
from flask import render_template
from flask import request
from flask import send_file
from flask import url_for

from app.all_questions.metadata_utils import generate_print_data_for_sections
from app.blueprints.fund_builder.forms.fund import FundForm
from app.blueprints.fund_builder.forms.round import RoundForm
from app.config_generator.generate_all_questions import print_html
from app.config_generator.generate_form import build_form_json
from app.db.models.fund import Fund
from app.db.models.round import Round
from app.db.queries.application import clone_single_round
Expand All @@ -25,6 +27,16 @@
from app.db.queries.fund import get_fund_by_id
from app.db.queries.round import add_round
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_form import build_form_json
from app.export_config.generate_fund_round_config import (
generate_application_display_config,
)
from app.export_config.generate_fund_round_config import generate_fund_config
from app.export_config.generate_fund_round_form_jsons import (
generate_form_jsons_for_round,
)
from app.export_config.generate_fund_round_html import generate_all_round_html
from config import Config

# Blueprint for routes used by v1 of FAB - using the DB
Expand Down Expand Up @@ -207,3 +219,29 @@ def view_all_questions(round_id):
)
html = print_html(print_data)
return render_template("view_questions.html", round=round, fund=fund, question_html=html)


@build_fund_bp.route("/create_export_files/<round_id>", methods=["GET"])
def create_export_files(round_id):
generate_form_jsons_for_round(round_id)
generate_all_round_html(round_id)
generate_application_display_config(round_id)
generate_fund_config(round_id)
round_short_name = get_round_by_id(round_id).short_name

# Directory to zip
directory_to_zip = f"app/export/config_generator/output/{round_short_name}/"
# Output zip file path (temporary)
output_zip_path = f"app/export/config_generator/output/{round_short_name}.zip"

# Create a zip archive of the directory
shutil.make_archive(output_zip_path.replace(".zip", ""), "zip", directory_to_zip)

# Ensure the file is removed after sending it
@after_this_request
def remove_file(response):
os.remove(output_zip_path)
return response

# Return the zipped folder for the user to download
return send_file(output_zip_path, as_attachment=True, download_name=f"{round_short_name}.zip")
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ <h2 class="govuk-heading-m">{{ fund.short_name }} - {{ round.short_name }}</h2>
"classes": "govuk-button--secondary"
})
}}
{{ govukButton({
"text": "Create export files for round",
"href": url_for("build_fund_bp.create_export_files", round_id=round.round_id),
"classes": "govuk-button--secondary"
})
}}
{% for section in round.sections %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
Expand Down
4 changes: 2 additions & 2 deletions app/blueprints/self_serve/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
from app.blueprints.self_serve.forms.page_form import PageForm
from app.blueprints.self_serve.forms.question_form import QuestionForm
from app.blueprints.self_serve.forms.section_form import SectionForm
from app.config_generator.generate_all_questions import print_html
from app.config_generator.generate_form import build_form_json
from app.export_config.generate_all_questions import print_html
from app.export_config.generate_form import build_form_json

FORM_RUNNER_URL = os.getenv("FORM_RUNNER_INTERNAL_HOST", "http://form-runner:3009")
FORM_RUNNER_URL_REDIRECT = os.getenv("FORM_RUNNER_EXTERNAL_HOST", "http://localhost:3009")
Expand Down
27 changes: 10 additions & 17 deletions app/blueprints/self_serve/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,23 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-m">What do you want to do?</h1>
<h2 class="govuk-heading-s">Template Setup</h2>
<h2 class="govuk-heading-s">Template Management</h2>
<ul class="govuk-body">
<li class="govuk-body"><a class="govuk-link" href="{{ url_for('self_serve_bp.question')}}">Add a
Question</a></li>
<li class="govuk-body"><a class="govuk-link" href="{{ url_for('self_serve_bp.question', template='edit') }}">Edit/Delete a
Question</a></li>
<li class="govuk-body"><a class="govuk-link" href="{{ url_for('self_serve_bp.page')}}">Create a
Page</a></li>
<li class="govuk-body"><a class="govuk-link" href="{{ url_for('self_serve_bp.page', template='edit') }}">Edit/Delete a
Page</a></li>
<li class="govuk-body"><a class="govuk-link" href="{{ url_for('self_serve_bp.form')}}">Create an
<li class="govuk-body"><a class="govuk-link" href="/">Edit a
template Question (text only)</a></li>
<li class="govuk-body"><a class="govuk-link" href="{{ url_for('self_serve_bp.form')}}">Create a template
Application Form</a></li>
<li class="govuk-body"><a class="govuk-link" href="{{ url_for('self_serve_bp.form', template='edit') }}">Edit/Delete an
Application Form</a></li>
<li class="govuk-body"><a class="govuk-link" href="{{ url_for('self_serve_bp.section')}}">Create a
Section (Group Forms)</a></li>
<li class="govuk-body"><a class="govuk-link" href="{{ url_for('self_serve_bp.section', template='edit') }}">Edit/Delete a
Section</a></li>
template Section (Form group)</a></li>
<li class="govuk-body"><a class="govuk-link" href="/">Edit a
template Section</a></li>
</ul>
<h2 class="govuk-heading-s">Fund Metadata</h2>
<h2 class="govuk-heading-s">Fund Configuration</h2>
<ul class="govuk-body">
<li class="govuk-body"><a class="govuk-link" href="{{url_for('build_fund_bp.fund')}}">Add a Fund</a></li>
<li class="govuk-body"><a class="govuk-link" href="{{url_for('build_fund_bp.round')}}">Add a Round</a></li>
<li class="govuk-body"><a class="govuk-link" href="{{url_for('build_fund_bp.view_fund')}}">View Fund and Round Config</a></li>
<li class="govuk-body"><a class="govuk-link" href="/">Configure a Round Application</a></li>
<li class="govuk-body"><a class="govuk-link" href="{{url_for('build_fund_bp.view_fund')}}">View Fund Config</a></li>
</ul>
</div>
</div>
Expand Down
Loading

0 comments on commit 15f07ec

Please sign in to comment.