Skip to content

Commit

Permalink
FS-4919 - Restructuring and rerouting template routes for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
wjrm500 committed Dec 27, 2024
1 parent f13442f commit 1b2d984
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 31 deletions.
34 changes: 3 additions & 31 deletions app/blueprints/template/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from werkzeug.utils import secure_filename

from app.blueprints.template.forms import TemplateFormForm, TemplateUploadForm
from app.db.models.application_config import Form
from app.blueprints.template.services import build_rows, json_import
from app.db.queries.application import (
delete_form,
get_all_template_forms,
Expand All @@ -15,42 +15,14 @@
)
from app.shared.helpers import error_formatter

# Blueprint for routes used by FAB PoC to manage templates
template_bp = Blueprint(
"template_bp",
__name__,
url_prefix="/template",
url_prefix="/templates",
template_folder="templates",
)


def json_import(data, template_name, filename):
from app.import_config.load_form_json import load_json_from_file

load_json_from_file(data=data, template_name=template_name, filename=filename)


def _build_rows(forms: list[Form]) -> list[dict]:
rows = []
for form in forms:
row = [
{
"html": "<a class='govuk-link--no-visited-state' "
f"href='{url_for('index_bp.preview_form', form_id=form.form_id)}'>{form.template_name}</a>"
},
{"text": form.name_in_apply_json["en"]},
{"text": form.runner_publish_name},
{
"html": "<a class='govuk-link--no-visited-state' href='"
f"{url_for('template_bp.edit_form_template', form_id=form.form_id, action='remove')}'>Delete</a> &nbsp;"
"<a class='govuk-link--no-visited-state' href='"
f"{url_for('template_bp.edit_form_template', form_id=form.form_id, action='edit')}'>Rename</a>"
},
]
rows.append(row)
return rows


@template_bp.route("/all", methods=["GET", "POST"])
def view_templates():
sections = get_all_template_sections()
Expand All @@ -59,7 +31,7 @@ def view_templates():
params = {
"sections": sections,
"forms": forms,
"form_template_rows": _build_rows(forms),
"form_template_rows": build_rows(forms),
"uploadform": form,
"breadcrumb_items": [
{"text": "Home", "href": url_for("index_bp.dashboard")},
Expand Down
30 changes: 30 additions & 0 deletions app/blueprints/template/services.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from flask import url_for

from app.db.models.application_config import Form


def json_import(data, template_name, filename):
from app.import_config.load_form_json import load_json_from_file

load_json_from_file(data, template_name, filename)


def build_rows(forms: list[Form]) -> list[dict]:
rows = []
for form in forms:
row = [
{
"html": "<a class='govuk-link--no-visited-state' "
f"href='{url_for('index_bp.preview_form', form_id=form.form_id)}'>{form.template_name}</a>"
},
{"text": form.name_in_apply_json["en"]},
{"text": form.runner_publish_name},
{
"html": "<a class='govuk-link--no-visited-state' href='"
f"{url_for('template_bp.edit_form_template', form_id=form.form_id, action='remove')}'>Delete</a> &nbsp;"
"<a class='govuk-link--no-visited-state' href='"
f"{url_for('template_bp.edit_form_template', form_id=form.form_id, action='edit')}'>Rename</a>"
},
]
rows.append(row)
return rows

0 comments on commit 1b2d984

Please sign in to comment.