handle errors better, fix form

This commit is contained in:
cellarspoon 2021-12-17 17:47:57 +01:00
parent 0ad3cea543
commit 0ccb4b426c
No known key found for this signature in database
GPG Key ID: 03789458B3D0C410
3 changed files with 22 additions and 10 deletions

9
app.py
View File

@ -118,6 +118,15 @@ def upload():
petname_message=pname_msg, petname_message=pname_msg,
generation_message=gen_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 = petname.generate()
pname_msg = "You have become {}".format(pname) pname_msg = "You have become {}".format(pname)

View File

@ -51,3 +51,7 @@ object {
max-height: 100%; max-height: 100%;
max-width: 100%; max-width: 100%;
} }
.error {
color: red;
}

View File

@ -11,6 +11,13 @@
</head> </head>
<body> <body>
<h1 class="title">Temporary Indexing</h1> <h1 class="title">Temporary Indexing</h1>
{% for field, errors in upload_form.errors.items() %}
<div class="error">
{{ upload_form[field].label }}: {{ ', '.join(errors) }}
</div>
{% endfor %}
<p> <p>
{{ petname_message}}. You are anonymous. You may reveal your identity {{ petname_message}}. You are anonymous. You may reveal your identity
later when saving your generated files. later when saving your generated files.
@ -21,14 +28,12 @@
{% endif %} {% endif %}
<div class="container"> <div class="container">
<div class="forms"> <div class="forms">
<form method="POST" action="/upload" enctype="multipart/form-data"> <form class="metafields" method="POST" action="/upload" enctype="multipart/form-data">
{{ upload_form.csrf_token }} {{ upload_form.csrf_token }}
{{ upload_form.metadata.label }} {{ upload_form.metadata.label }}
{{ upload_form.metadata }} {{ upload_form.metadata }}
</form>
<form class="metafields" method="POST" action="/upload" enctype="multipart/form-data">
{{ upload_form.title.label }} {{ upload_form.title.label }}
{{ upload_form.title }} {{ upload_form.title }}
@ -54,14 +59,8 @@
<input type="submit" value="generate" /> <input type="submit" value="generate" />
</form> </form>
{% if upload_form.metadata.errors %}
<ul class="errors">
{% for error in upload_form.metadata.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
</div> </div>
<div class="iframe"> <div class="iframe">
<object data="{{ pdf }}" type="application/pdf"> <object data="{{ pdf }}" type="application/pdf">
<iframe src="{{ pdf }}"></iframe> <iframe src="{{ pdf }}"></iframe>