diff --git a/app/blueprints/fund_builder/routes.py b/app/blueprints/fund_builder/routes.py index a280d969..3f8d58d9 100644 --- a/app/blueprints/fund_builder/routes.py +++ b/app/blueprints/fund_builder/routes.py @@ -42,10 +42,7 @@ 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_config import generate_config_for_round from app.export_config.generate_fund_round_form_jsons import ( generate_form_jsons_for_round, ) @@ -373,8 +370,7 @@ def view_form_questions(round_id, form_id): 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) + generate_config_for_round(round_id) round_short_name = get_round_by_id(round_id).short_name # Directory to zip diff --git a/app/export_config/generate_fund_round_config.py b/app/export_config/generate_fund_round_config.py index 6cd7fe35..8874f60f 100644 --- a/app/export_config/generate_fund_round_config.py +++ b/app/export_config/generate_fund_round_config.py @@ -32,6 +32,8 @@ "COF_R4_W2": 11, } +TEMPLATE_FUND_ROUND_EXPORT = {"sections_config": [], "fund_config": {}, "round_config": [], "base_path": None} + def generate_application_display_config(round_id): @@ -39,6 +41,8 @@ def generate_application_display_config(round_id): # get round round = get_round_by_id(round_id) round_base_path = ROUND_BASE_PATHS.get(round.short_name, 0) # so this works for dummy data + application_base_path = f"{round_base_path}.1" + TEMPLATE_FUND_ROUND_EXPORT["base_path"] = round_base_path "sort by Section.index" sections = db.session.query(Section).filter(Section.round_id == round_id).order_by(Section.index).all() current_app.logger.info(f"Generating application display config for round {round_id}") @@ -51,7 +55,9 @@ def generate_application_display_config(round_id): f"{section.index}. {section.name_in_apply_json['cy']}" if section.name_in_apply_json.get("cy") else "" ) ordered_sections.append( - FundSectionSection(section_name=section.name_in_apply_json, tree_path=f"{round_base_path}.{section.index}") + FundSectionSection( + section_name=section.name_in_apply_json, tree_path=f"{application_base_path}.{section.index}" + ).as_dict() ) forms = db.session.query(Form).filter(Form.section_id == section.section_id).order_by(Form.section_index).all() for original_form in forms: @@ -72,9 +78,9 @@ def generate_application_display_config(round_id): section_name=form.name_in_apply_json, form_name_json=form.runner_publish_name, tree_path=f"{round_base_path}.{section.index}.{form.section_index}", - ) + ).as_dict() ) - write_config(ordered_sections, "sections_config", round.short_name, "python_file") + return ordered_sections def generate_fund_config(round_id): @@ -90,11 +96,11 @@ def generate_fund_config(round_id): short_name=fund.short_name, description_json=fund.description_json, welsh_available=fund.welsh_available, - owner_organisation_name=fund.owner_organisation.name, - owner_organisation_shortname=fund.owner_organisation.short_name, - owner_organisation_logo_uri=fund.owner_organisation.logo_uri, + owner_organisation_name=None, + owner_organisation_shortname=None, + owner_organisation_logo_uri=None, ) - write_config(fund_export, "fund_config", round.short_name, "python_file") + return fund_export.as_dict() def generate_round_config(round_id): @@ -134,7 +140,7 @@ def generate_round_config(round_id): feedback_survey_config=round.feedback_survey_config, ) - write_config(round_export, "round_config", round.short_name, "python_file") + return round_export.as_dict() def generate_config_for_round(round_id): @@ -155,6 +161,11 @@ def generate_config_for_round(round_id): """ if round_id is None: raise ValueError("Valid round ID is required to generate configuration.") - generate_fund_config(round_id) - generate_round_config(round_id) - generate_application_display_config(round_id) + fund_config = generate_fund_config(round_id) + TEMPLATE_FUND_ROUND_EXPORT["fund_config"] = fund_config + round_config = generate_round_config(round_id) + TEMPLATE_FUND_ROUND_EXPORT["round_config"] = round_config + round_display_config = generate_application_display_config(round_id) + TEMPLATE_FUND_ROUND_EXPORT["sections_config"] = round_display_config + fund_round_export = TEMPLATE_FUND_ROUND_EXPORT + write_config(fund_round_export, "round_config", fund_round_export["round_config"]["short_name"], "python_file") diff --git a/app/shared/data_classes.py b/app/shared/data_classes.py index c58b151d..2484b3aa 100644 --- a/app/shared/data_classes.py +++ b/app/shared/data_classes.py @@ -1,3 +1,4 @@ +from dataclasses import asdict from dataclasses import dataclass from dataclasses import field from typing import Dict @@ -31,6 +32,9 @@ class FundSectionBase: section_name: SectionName tree_path: str + def as_dict(self): + return asdict(self) + @dataclass class FundSectionSection(FundSectionBase): @@ -69,7 +73,7 @@ class ContactUsBannerJson: @dataclass class FeedbackSurveyConfig: has_feedback_survey: Optional[bool] = None - has_section_feedback: Optional[bool] = None + has_section_feedback: Optional[bool] = False is_feedback_survey_optional: Optional[bool] = None is_section_feedback_optional: Optional[bool] = None @@ -91,6 +95,9 @@ class FundExport: title_json: TitleJson = field(default_factory=TitleJson) description_json: DescriptionJson = field(default_factory=DescriptionJson) + def as_dict(self): + return asdict(self) + @dataclass class RoundExport: @@ -123,9 +130,19 @@ class RoundExport: is_expression_of_interest: Optional[bool] = None eoi_decision_schema: Optional[Dict[str, str]] = None # check to use FeedbackSurveyConfig - feedback_survey_config: Optional[Dict[str, str]] = None + feedback_survey_config: Optional[Dict[str, str]] = ( + { + "has_feedback_survey": False, + "has_section_feedback": False, + "is_feedback_survey_optional": False, + "is_section_feedback_optional": False, + }, + ) # check to use EligibilityConfig - eligibility_config: Optional[Dict[str, str]] = None + eligibility_config: Optional[Dict[str, str]] = {"has_eligibility": False} title_json: TitleJson = field(default_factory=TitleJson) # check to use EligibilityConfig contact_us_banner_json: Optional[Dict[str, str]] = None + + def as_dict(self): + return asdict(self)