From 2c69fd5bbe3c2eeab37bd84ac86aa7e299f404a5 Mon Sep 17 00:00:00 2001 From: cellarspoon Date: Fri, 17 Dec 2021 18:35:59 +0100 Subject: [PATCH] handle missing metadata edge case --- app.py | 15 ++++++++++++++- static/styles.css | 4 ++++ templates/index.html | 10 ++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index 237ddee..d318897 100644 --- a/app.py +++ b/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) diff --git a/static/styles.css b/static/styles.css index c8e24dd..08abfdd 100644 --- a/static/styles.css +++ b/static/styles.css @@ -24,6 +24,10 @@ div.iframe { border: 2px solid blue; } +ul { + padding: 0; +} + ul li { list-style: none; } diff --git a/templates/index.html b/templates/index.html index 83c617d..543be4d 100644 --- a/templates/index.html +++ b/templates/index.html @@ -12,6 +12,16 @@

Temporary Indexing

+ {% with messages = get_flashed_messages() %} + {% if messages %} + + {% endif %} + {% endwith %} + {% for field, errors in upload_form.errors.items() %}
{{ upload_form[field].label }}: {{ ', '.join(errors) }}