diff --git a/app/blueprints/template/routes.py b/app/blueprints/template/routes.py index 82e45284..e403b800 100644 --- a/app/blueprints/template/routes.py +++ b/app/blueprints/template/routes.py @@ -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, @@ -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": "{form.template_name}" - }, - {"text": form.name_in_apply_json["en"]}, - {"text": form.runner_publish_name}, - { - "html": "Delete  " - "Rename" - }, - ] - rows.append(row) - return rows - - @template_bp.route("/all", methods=["GET", "POST"]) def view_templates(): sections = get_all_template_sections() @@ -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")}, diff --git a/app/blueprints/template/services.py b/app/blueprints/template/services.py new file mode 100644 index 00000000..eeab9039 --- /dev/null +++ b/app/blueprints/template/services.py @@ -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": "{form.template_name}" + }, + {"text": form.name_in_apply_json["en"]}, + {"text": form.runner_publish_name}, + { + "html": "Delete  " + "Rename" + }, + ] + rows.append(row) + return rows