one form to rule them all
This commit is contained in:
parent
b827f6cbe1
commit
a98fe6f5d1
23
app.py
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)
|
||||
|
@ -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…
Reference in New Issue
Block a user