Skip to content

Commit

Permalink
FS-4919 - Moving all funds as GOV.UK select items helper function to …
Browse files Browse the repository at this point in the history
…shared helpers module
  • Loading branch information
wjrm500 committed Dec 27, 2024
1 parent a89797c commit fd76f63
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
3 changes: 1 addition & 2 deletions app/blueprints/fund/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
8 changes: 0 additions & 8 deletions app/blueprints/index/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/<form_id>", methods=["GET"])
def preview_form(form_id):
"""
Expand Down
3 changes: 1 addition & 2 deletions app/blueprints/round/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
8 changes: 8 additions & 0 deletions app/shared/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

0 comments on commit fd76f63

Please sign in to comment.