Browse Source

handle errors better, fix form

main
cellarspoon 3 years ago
parent
commit
0ccb4b426c
No known key found for this signature in database GPG Key ID: 3789458B3D0C410
  1. 9
      app.py
  2. 4
      static/styles.css
  3. 19
      templates/index.html

9
app.py

@ -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)

4
static/styles.css

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

19
templates/index.html

@ -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>

Loading…
Cancel
Save