From 0ccb4b426cabc92140fa860b2de0e86fb2579c44 Mon Sep 17 00:00:00 2001 From: cellarspoon Date: Fri, 17 Dec 2021 17:47:57 +0100 Subject: [PATCH] handle errors better, fix form --- app.py | 9 +++++++++ static/styles.css | 4 ++++ templates/index.html | 19 +++++++++---------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/app.py b/app.py index 6ea8aed..206a4ca 100644 --- a/app.py +++ b/app.py @@ -118,6 +118,15 @@ def upload(): petname_message=pname_msg, generation_message=gen_msg, ) + else: + pname = upload_form.petname.data + pname_msg = "You are still {}".format(pname) + return render_template( + "index.html", + upload_form=upload_form, + petname_message=pname_msg, + petname=pname, + ) pname = petname.generate() pname_msg = "You have become {}".format(pname) diff --git a/static/styles.css b/static/styles.css index 017a99c..ba4ceb2 100644 --- a/static/styles.css +++ b/static/styles.css @@ -51,3 +51,7 @@ object { max-height: 100%; max-width: 100%; } + +.error { + color: red; +} diff --git a/templates/index.html b/templates/index.html index 1cf0748..c488e4a 100644 --- a/templates/index.html +++ b/templates/index.html @@ -11,6 +11,13 @@

Temporary Indexing

+ + {% for field, errors in upload_form.errors.items() %} +
+ {{ upload_form[field].label }}: {{ ', '.join(errors) }} +
+ {% endfor %} +

{{ petname_message}}. You are anonymous. You may reveal your identity later when saving your generated files. @@ -21,14 +28,12 @@ {% endif %}

-
+ {{ upload_form.csrf_token }} {{ upload_form.metadata.label }} {{ upload_form.metadata }} -
-
{{ upload_form.title.label }} {{ upload_form.title }} @@ -54,14 +59,8 @@
- {% if upload_form.metadata.errors %} -
    - {% for error in upload_form.metadata.errors %} -
  • {{ error }}
  • - {% endfor %} -
- {% endif %}
+