handle missing metadata edge case

This commit is contained in:
cellarspoon 2021-12-17 18:35:59 +01:00
parent 511d8075e2
commit 2c69fd5bbe
No known key found for this signature in database
GPG Key ID: 03789458B3D0C410
3 changed files with 28 additions and 1 deletions

15
app.py
View File

@ -4,7 +4,7 @@ import string
from pathlib import Path
import petname
from flask import Flask, redirect, render_template, request, url_for
from flask import Flask, flash, redirect, render_template, request, url_for
from flask_wtf import FlaskForm
from flask_wtf.csrf import CSRFProtect
from flask_wtf.file import FileAllowed, FileField, FileRequired
@ -74,6 +74,19 @@ def upload():
upload_form = UploadForm()
if upload_form.validate_on_submit():
if not upload_form.metadata.data:
pname = upload_form.petname.data
metadata_name = "metadata-{}.db".format(pname)
if not Path(os.path.join(CWD, "metadatum", metadata_name)).exists():
flash("Woops, you forgot to upload a metadata file?")
pname_msg = "You are still {}".format(pname)
return render_template(
"index.html",
upload_form=upload_form,
petname_message=pname_msg,
petname=pname,
)
pname = upload_form.petname.data
pname_msg = "You are still {}".format(pname)

View File

@ -24,6 +24,10 @@ div.iframe {
border: 2px solid blue;
}
ul {
padding: 0;
}
ul li {
list-style: none;
}

View File

@ -12,6 +12,16 @@
<body>
<h1 class="title">Temporary Indexing</h1>
{% with messages = get_flashed_messages() %}
{% if messages %}
<ul class=flashes>
{% for message in messages %}
<li>{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
{% endwith %}
{% for field, errors in upload_form.errors.items() %}
<div class="error">
{{ upload_form[field].label }}: {{ ', '.join(errors) }}