one form to rule them all

This commit is contained in:
cellarspoon 2021-12-06 11:17:33 +01:00
parent b827f6cbe1
commit a98fe6f5d1
No known key found for this signature in database
GPG Key ID: 03789458B3D0C410
2 changed files with 10 additions and 22 deletions

23
app.py
View File

@ -21,46 +21,33 @@ class UploadForm(FlaskForm):
metadata = FileField(
validators=[FileAllowed(["db"], "Metadata databases only"), FileRequired()]
)
class CardSidesForm(FlaskForm):
title = RadioField("title", choices=[("side a", "side a"), ("side b", "side b")])
@app.route("/")
def home():
upload_form = UploadForm()
card_sides_form = CardSidesForm()
return render_template(
"index.html", upload_form=upload_form, card_sides_form=card_sides_form
)
return render_template("index.html", upload_form=upload_form)
@app.route("/upload", methods=["POST"])
def upload():
upload_form = UploadForm()
card_sides_form = CardSidesForm()
if upload_form.validate_on_submit():
f = upload_form.metadata.data
filename = secure_filename(f.filename)
f.save(os.path.join(CWD, "metadatum", filename))
return redirect(url_for("home"))
return render_template(
"index.html", upload_form=upload_form, card_sides_form=card_sides_form
)
return render_template("index.html", upload_form=upload_form)
@app.route("/generate", methods=["POST"])
def generate():
upload_form = UploadForm()
card_sides_form = CardSidesForm()
if card_sides_form.validate_on_submit():
print(card_sides_form.title.data)
if upload_form.validate_on_submit():
print(upload_form.title.data)
else:
print("didnt work")
return render_template(
"index.html", upload_form=upload_form, card_sides_form=card_sides_form
)
return render_template("index.html", upload_form=upload_form)

View File

@ -7,7 +7,11 @@
</head>
<body>
<form method="POST" action="/upload" enctype="multipart/form-data">
{{ upload_form.csrf_token }} {{ upload_form.metadata }}
{{ upload_form.csrf_token }}
{{ upload_form.metadata }}
{{ upload_form.title }}
<input type="submit" value="Go" />
</form>
@ -19,9 +23,6 @@
</ul>
{% endif %}
<form method="POST" action="/generate" enctype="multipart/form-data">
{{ card_sides_form.csrf_token }} {{ card_sides_form.title }}
<input type="submit" value="Go" />
</form>
</body>
</html>