From 5143b1e155dcf90ab5c5a49dd4ffe7ceaf74a271 Mon Sep 17 00:00:00 2001 From: Thomas Schneider <thomas@fsmpi.rwth-aachen.de> Date: Tue, 10 Sep 2024 17:23:16 +0200 Subject: [PATCH] templates/schild: Show Flask flashes and WTForms errors --- schilder2000/templates/schild.html.j2 | 32 ++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/schilder2000/templates/schild.html.j2 b/schilder2000/templates/schild.html.j2 index c6a1008..40aeed2 100644 --- a/schilder2000/templates/schild.html.j2 +++ b/schilder2000/templates/schild.html.j2 @@ -1,12 +1,20 @@ {% extends "_base.html.j2" %} -{% macro render_field(field) -%} +{% macro render_field(field, class="") -%} {% if field.type == "CSRFTokenField" -%} {{ field }} {%- else -%} <div class="box"> - {{ field.label(class="for-text") }} - {{ field(class="input-dispatch") }} + {%- set error = ' error' if field.errors else '' -%} + {{ field.label(class="for-text"+error) }} + {{ field(class=class+error) }} + {%- if field.errors -%} + <ul class="errors"> + {%- for err in field.errors -%} + <li>{{ err|e }}</li> + {%- endfor -%} + </ul> + {%- endif -%} </div> {%- endif -%} {%- endmacro %} @@ -20,11 +28,24 @@ {%- endblock title %} {% block main -%} + <section> + {%- with messages = get_flashed_messages() -%} + {%- if messages -%} + <ul class="flashes"> + {%- for m in messages -%} + <li>{{ m }}</li> + {%- endfor -%} + </ul> + {%- endif -%} + {%- endwith -%} + </section> + + <section> <form method="post" action=""> {{ form.csrf_token }} - {{ render_field(form.title) }} - {{ render_field(form.text) }} + {{ render_field(form.title, "input-dispatch") }} + {{ render_field(form.text, "input-dispatch") }} <fieldset class="templateselect"> <legend>Vorlage</legend> @@ -85,6 +106,7 @@ {%- endif -%} </div> </form> + </section> {%- if schild %} <div> -- GitLab