handle missing metadata edge case
This commit is contained in:
parent
511d8075e2
commit
2c69fd5bbe
15
app.py
15
app.py
@ -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)
|
||||
|
||||
|
@ -24,6 +24,10 @@ div.iframe {
|
||||
border: 2px solid blue;
|
||||
}
|
||||
|
||||
ul {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
ul li {
|
||||
list-style: none;
|
||||
}
|
||||
|
@ -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) }}
|
||||
|
Loading…
Reference in New Issue
Block a user