diff --git a/app/blueprints/fund/routes.py b/app/blueprints/fund/routes.py index fcad5af6..a1a94bc3 100644 --- a/app/blueprints/fund/routes.py +++ b/app/blueprints/fund/routes.py @@ -10,10 +10,9 @@ ) from app.blueprints.fund.forms import FundForm -from app.blueprints.index.routes import all_funds_as_govuk_select_items from app.db.models.fund import Fund, FundingType from app.db.queries.fund import add_fund, get_all_funds, get_fund_by_id, update_fund -from app.shared.helpers import error_formatter +from app.shared.helpers import all_funds_as_govuk_select_items, error_formatter INDEX_BP_DASHBOARD = "index_bp.dashboard" diff --git a/app/blueprints/index/routes.py b/app/blueprints/index/routes.py index b7a1cae6..ef0aa118 100644 --- a/app/blueprints/index/routes.py +++ b/app/blueprints/index/routes.py @@ -45,14 +45,6 @@ def dashboard(): return render_template("dashboard.html") -def all_funds_as_govuk_select_items(all_funds: list) -> list: - """ - Reformats a list of funds into a list of display/value items that can be passed to a govUk select macro - in the html - """ - return [{"text": f"{f.short_name} - {f.name_json['en']}", "value": str(f.fund_id)} for f in all_funds] - - @index_bp.route("/preview/", methods=["GET"]) def preview_form(form_id): """ diff --git a/app/blueprints/round/routes.py b/app/blueprints/round/routes.py index 8b9bd22f..ee0dd22a 100644 --- a/app/blueprints/round/routes.py +++ b/app/blueprints/round/routes.py @@ -11,13 +11,12 @@ url_for, ) -from app.blueprints.index.routes import all_funds_as_govuk_select_items from app.blueprints.round.forms import RoundForm, get_datetime from app.db.models.round import Round from app.db.queries.clone import clone_single_round from app.db.queries.fund import get_all_funds from app.db.queries.round import add_round, get_round_by_id, update_round -from app.shared.helpers import error_formatter +from app.shared.helpers import all_funds_as_govuk_select_items, error_formatter INDEX_BP_DASHBOARD = "index_bp.dashboard" diff --git a/app/shared/helpers.py b/app/shared/helpers.py index 36ab32ce..bc3f8595 100644 --- a/app/shared/helpers.py +++ b/app/shared/helpers.py @@ -63,3 +63,11 @@ def no_spaces_between_letters(form, field): return if re.search(r"\b\w+\s+\w+\b", field.data): # Matches sequences with spaces in between raise ValidationError("Spaces between letters are not allowed.") + + +def all_funds_as_govuk_select_items(all_funds: list) -> list: + """ + Reformats a list of funds into a list of display/value items that can be passed to a govUk select macro + in the html + """ + return [{"text": f"{f.short_name} - {f.name_json['en']}", "value": str(f.fund_id)} for f in all_funds]