Skip to content

Commit

Permalink
temp changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam-W1 committed Oct 1, 2024
1 parent e4decbb commit fbe0d05
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 20 deletions.
8 changes: 2 additions & 6 deletions app/blueprints/fund_builder/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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
Expand Down
33 changes: 22 additions & 11 deletions app/export_config/generate_fund_round_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@
"COF_R4_W2": 11,
}

TEMPLATE_FUND_ROUND_EXPORT = {"sections_config": [], "fund_config": {}, "round_config": [], "base_path": None}


def generate_application_display_config(round_id):

ordered_sections = []
# 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}")
Expand All @@ -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:
Expand All @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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")
23 changes: 20 additions & 3 deletions app/shared/data_classes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from dataclasses import asdict
from dataclasses import dataclass
from dataclasses import field
from typing import Dict
Expand Down Expand Up @@ -31,6 +32,9 @@ class FundSectionBase:
section_name: SectionName
tree_path: str

def as_dict(self):
return asdict(self)


@dataclass
class FundSectionSection(FundSectionBase):
Expand Down Expand Up @@ -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

Expand All @@ -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:
Expand Down Expand Up @@ -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)

0 comments on commit fbe0d05

Please sign in to comment.