Browse Source

handle missing metadata edge case

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

15
app.py

@ -4,7 +4,7 @@ import string
from pathlib import Path from pathlib import Path
import petname 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 import FlaskForm
from flask_wtf.csrf import CSRFProtect from flask_wtf.csrf import CSRFProtect
from flask_wtf.file import FileAllowed, FileField, FileRequired from flask_wtf.file import FileAllowed, FileField, FileRequired
@ -74,6 +74,19 @@ def upload():
upload_form = UploadForm() upload_form = UploadForm()
if upload_form.validate_on_submit(): 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 = upload_form.petname.data
pname_msg = "You are still {}".format(pname) pname_msg = "You are still {}".format(pname)

4
static/styles.css

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

10
templates/index.html

@ -12,6 +12,16 @@
<body> <body>
<h1 class="title">Temporary Indexing</h1> <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() %} {% for field, errors in upload_form.errors.items() %}
<div class="error"> <div class="error">
{{ upload_form[field].label }}: {{ ', '.join(errors) }} {{ upload_form[field].label }}: {{ ', '.join(errors) }}

Loading…
Cancel
Save