diff --git a/app/main/views/styleguide.py b/app/main/views/styleguide.py index 92fdda53de..3b710ba9b1 100644 --- a/app/main/views/styleguide.py +++ b/app/main/views/styleguide.py @@ -1,9 +1,14 @@ -from flask import abort, current_app, render_template +from flask import abort, current_app, flash, render_template, redirect, request, url_for from flask_wtf import FlaskForm as Form +from flask_babel import _ from notifications_utils.template import Template from wtforms import FileField, PasswordField, StringField, TextAreaField, validators +from app import (get_current_locale, template_category_api_client) from app.main import main +from app.main.forms import EmailTemplateFormWithCategory +from app.models.enum.template_categories import DefaultTemplateCategories + @main.route("/_styleguide") @@ -27,3 +32,38 @@ class FormExamples(Form): template = Template({"content": sms}) return render_template("views/styleguide.html", form=form, template=template) + + +@main.route("/_categories", methods=["GET", "POST"]) +def categories(): + if not current_app.config["SHOW_STYLEGUIDE"]: + abort(404) + + form = EmailTemplateFormWithCategory() + categories = template_category_api_client.get_all_template_categories() + + other_category = {DefaultTemplateCategories.LOW.value: form.template_category_other} + + name_col = "name_en" if get_current_locale(current_app) == "en" else "name_fr" + desc_col = "description_en" if get_current_locale(current_app) == "en" else "description_fr" + categories = sorted(categories, key=lambda x: x[name_col]) + form.template_category_id.choices = [(cat["id"], cat[name_col]) for cat in categories if not cat.get("hidden", False)] + + form.template_category_id.choices.append((DefaultTemplateCategories.LOW.value, _("Other"))) + template_category_hints = {cat["id"]: cat[desc_col] for cat in categories} + + form.name.data = "name" + form.subject.data = "subject" + form.template_content.data = "content" + + if form.validate_on_submit(): + flash(_("Category saved"), "default_with_tick") + + return render_template( + "views/categories.html", + form=form, + template_category_hints=template_category_hints, + other_category=other_category, + heading=_("Category"), + template_category_mode=None, + ) diff --git a/app/templates/views/categories.html b/app/templates/views/categories.html new file mode 100644 index 0000000000..2c66d9a7ae --- /dev/null +++ b/app/templates/views/categories.html @@ -0,0 +1,60 @@ +{% extends "admin_template.html" %} +{% from "components/textbox.html" import textbox %} +{% from "components/page-header.html" import page_header %} +{% from "components/page-footer.html" import sticky_page_footer %} +{% from "components/radios.html" import radios %} +{% from "components/select-input.html" import select %} +{% from "components/form.html" import form_wrapper %} +{% from "components/task-shortcut.html" import task_shortcut %} +{% from "components/template-category.html" import template_category %} + +{% block service_page_title %} +{{ heading }} +{% endblock %} + +{% block maincolumn_content %} +{{ page_header(heading) }} +{% call form_wrapper() %} + +
+
+ + {% if config["FF_TEMPLATE_CATEGORY"] %} +

{{ _('Template category') }}

+ {% call template_category(form.template_category_id, true if template_category_mode == 'expand' else false) %} + {{ select(form.template_category_id, hint=_('Template categories help improve delivery of your messages'), + option_hints=template_category_hints, option_conditionals=other_category, testid="template-categories", + use_aria_labelledby=false) }} + {% endcall %} + {% endif %} + {{ sticky_page_footer(_('Save')) }} +
+
+{% endcall %} +{% endblock %} + +{% block page_script %} +{{ super() }} + + +{% endblock %} \ No newline at end of file diff --git a/app/translations/csv/fr.csv b/app/translations/csv/fr.csv index 460d263830..3e3d1b6364 100644 --- a/app/translations/csv/fr.csv +++ b/app/translations/csv/fr.csv @@ -1972,5 +1972,6 @@ "Alternative text","Texte de remplacement" "Provide an accessible description of your logo","Fournissez une description accessible de votre logo" "Category","Catégorie" +"Category saved","Catégorie enregistrée" "Does the category still apply?","La catégorie s'applique-t-elle toujours?" "Review your activity","Examinez votre activité" \ No newline at end of file