diff --git a/app/blueprints/fund_builder/forms/fund.py b/app/blueprints/fund_builder/forms/fund.py index 3a8f552..52b21b4 100644 --- a/app/blueprints/fund_builder/forms/fund.py +++ b/app/blueprints/fund_builder/forms/fund.py @@ -1,3 +1,5 @@ +from enum import Enum + from flask_wtf import FlaskForm from wtforms import HiddenField from wtforms import RadioField @@ -5,6 +7,27 @@ from wtforms.validators import DataRequired from wtforms.validators import Length +from app.db.models.fund import FundingType + + +class GovUkRadioEnumField(RadioField): + source_enum: Enum + gov_uk_choices: list + + def __init__(self, name: str, _prefix, _translations, label: str, _form, source_enum: Enum): + super().__init__( + name=name, + label=label, + _form=_form, + _prefix=_prefix, + _translations=_translations, + choices=[(value.name, value.value) for value in source_enum], + ) + self.source_enum = source_enum + self.gov_uk_choices = [ + {"text": value.get_text_for_display(), "value": value.value} for value in self.source_enum + ] + class FundForm(FlaskForm): fund_id = HiddenField("Fund ID") @@ -13,3 +36,4 @@ class FundForm(FlaskForm): short_name = StringField("Short Name", validators=[DataRequired(), Length(max=6)]) description_en = StringField("Description", validators=[DataRequired()]) welsh_available = RadioField("Welsh Available", choices=[("true", "Yes"), ("false", "No")], default="false") + funding_type = GovUkRadioEnumField(label="Funding Type", source_enum=FundingType) diff --git a/app/blueprints/fund_builder/routes.py b/app/blueprints/fund_builder/routes.py index 4ad8753..0942e60 100644 --- a/app/blueprints/fund_builder/routes.py +++ b/app/blueprints/fund_builder/routes.py @@ -21,6 +21,7 @@ from app.blueprints.fund_builder.forms.round import get_datetime from app.blueprints.fund_builder.forms.section import SectionForm from app.db.models.fund import Fund +from app.db.models.fund import FundingType from app.db.models.round import Round from app.db.queries.application import clone_single_form from app.db.queries.application import clone_single_round @@ -221,6 +222,7 @@ def fund(fund_id=None): "short_name": fund.short_name, "description_en": fund.description_json.get("en", ""), "welsh_available": "true" if fund.welsh_available else "false", + "funding_type": fund.funding_type.value, } form = FundForm(data=fund_data) else: @@ -234,6 +236,7 @@ def fund(fund_id=None): fund.welsh_available = form.welsh_available.data == "true" fund.short_name = form.short_name.data fund.audit_info = {"user": "dummy_user", "timestamp": datetime.now().isoformat(), "action": "update"} + fund.funding_type = form.funding_type.data update_fund(fund) flash(f"Updated fund {form.title_en.data}") else: @@ -244,6 +247,7 @@ def fund(fund_id=None): welsh_available=form.welsh_available.data == "true", short_name=form.short_name.data, audit_info={"user": "dummy_user", "timestamp": datetime.now().isoformat(), "action": "create"}, + funding_type=FundingType(form.funding_type.data), ) add_fund(new_fund) flash(f"Created fund {form.name_en.data}") @@ -522,6 +526,7 @@ def view_form_questions(round_id, form_id): "view_questions.html", round=round, fund=fund, question_html=html, title=form.name_in_apply_json["en"] ) + def create_export_zip(directory_to_zip, zip_file_name) -> str: # Output zip file path (temporary) output_zip_path = Config.TEMP_FILE_PATH / zip_file_name @@ -538,7 +543,9 @@ def create_export_files(round_id): generate_config_for_round(round_id) round_short_name = get_round_by_id(round_id).short_name - output_zip_path = create_export_zip(directory_to_zip=Config.TEMP_FILE_PATH / round_short_name, zip_file_name=round_short_name) + output_zip_path = create_export_zip( + directory_to_zip=Config.TEMP_FILE_PATH / round_short_name, zip_file_name=round_short_name + ) # Ensure the file is removed after sending it @after_this_request diff --git a/app/blueprints/fund_builder/templates/fund.html b/app/blueprints/fund_builder/templates/fund.html index dcff26d..80f6858 100644 --- a/app/blueprints/fund_builder/templates/fund.html +++ b/app/blueprints/fund_builder/templates/fund.html @@ -2,6 +2,7 @@ {% set pageHeading %}{{ 'Update a Fund' if fund_id else 'Create a Fund' }} {% endset %} {% from "macros/wtfToGovUk.html" import input %} {% from "macros/wtfToGovUk.html" import yes_no %} +{% from "macros/wtfToGovUk.html" import radios_from_enum %} {%- from "govuk_frontend_jinja/components/button/macro.html" import govukButton -%} {% block content %}