Browse Source

one form to rule them all

main
cellarspoon 2 years ago
parent
commit
a98fe6f5d1
No known key found for this signature in database GPG Key ID: 3789458B3D0C410
  1. 23
      app.py
  2. 9
      templates/index.html

23
app.py

@ -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)

9
templates/index.html

@ -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>

Loading…
Cancel
Save