|
@ -6,7 +6,7 @@ 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 |
|
|
from werkzeug.utils import secure_filename |
|
|
from werkzeug.utils import secure_filename |
|
|
from wtforms import StringField |
|
|
from wtforms import RadioField, StringField |
|
|
from wtforms.validators import DataRequired |
|
|
from wtforms.validators import DataRequired |
|
|
|
|
|
|
|
|
app = Flask(__name__) |
|
|
app = Flask(__name__) |
|
@ -21,18 +21,44 @@ class UploadForm(FlaskForm): |
|
|
pdf = FileField(validators=[FileAllowed(["pdf"], "PDFs only!"), FileRequired()]) |
|
|
pdf = FileField(validators=[FileAllowed(["pdf"], "PDFs only!"), FileRequired()]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CardSidesForm(FlaskForm): |
|
|
|
|
|
title = RadioField("title", choices=[("side a", "side a"), ("side b", "side b")]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/") |
|
|
@app.route("/") |
|
|
def home(): |
|
|
def home(): |
|
|
form = UploadForm() |
|
|
upload_form = UploadForm() |
|
|
return render_template("index.html", form=form) |
|
|
card_sides_form = CardSidesForm() |
|
|
|
|
|
return render_template( |
|
|
|
|
|
"index.html", upload_form=upload_form, card_sides_form=card_sides_form |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/upload", methods=["POST"]) |
|
|
@app.route("/upload", methods=["POST"]) |
|
|
def upload(): |
|
|
def upload(): |
|
|
form = UploadForm() |
|
|
upload_form = UploadForm() |
|
|
if form.validate_on_submit(): |
|
|
card_sides_form = CardSidesForm() |
|
|
f = form.pdf.data |
|
|
|
|
|
|
|
|
if upload_form.validate_on_submit(): |
|
|
|
|
|
f = upload_form.pdf.data |
|
|
filename = secure_filename(f.filename) |
|
|
filename = secure_filename(f.filename) |
|
|
f.save(os.path.join(CWD, "pdfs", filename)) |
|
|
f.save(os.path.join(CWD, "pdfs", filename)) |
|
|
return redirect(url_for("home")) |
|
|
return redirect(url_for("home")) |
|
|
return render_template("index.html", form=form) |
|
|
return render_template( |
|
|
|
|
|
"index.html", upload_form=upload_form, card_sides_form=card_sides_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) |
|
|
|
|
|
else: |
|
|
|
|
|
print("didnt work") |
|
|
|
|
|
|
|
|
|
|
|
return render_template( |
|
|
|
|
|
"index.html", upload_form=upload_form, card_sides_form=card_sides_form |
|
|
|
|
|
) |
|
|