You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

65 lines
1.9 KiB

import os
from pathlib import Path
from flask import Flask, redirect, render_template, url_for
from flask_wtf import FlaskForm
from flask_wtf.csrf import CSRFProtect
from flask_wtf.file import FileAllowed, FileField, FileRequired
from werkzeug.utils import secure_filename
from wtforms import RadioField, StringField
from wtforms.validators import DataRequired
app = Flask(__name__)
app.config["SECRET_KEY"] = "foo"
app.config["WTF_CSRF_SECRET_KEY"] = "bar"
CWD = Path().resolve()
class UploadForm(FlaskForm):
metadata = FileField(
"Metadata file",
validators=[FileAllowed(["db"], "Metadata databases only"), FileRequired()],
)
title = RadioField("title", choices=[("side a", "side a"), ("side b", "side b")])
author = RadioField("author", choices=[("side a", "side a"), ("side b", "side b")])
tags = RadioField("tags", choices=[("side a", "side a"), ("side b", "side b")])
comments = RadioField(
"comments", choices=[("side a", "side a"), ("side b", "side b")]
)
timestamp = RadioField(
"timestamp", choices=[("side a", "side a"), ("side b", "side b")]
)
@app.route("/")
def home():
upload_form = UploadForm()
return render_template("index.html", upload_form=upload_form)
@app.route("/upload", methods=["POST"])
def upload():
upload_form = UploadForm()
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)
@app.route("/generate", methods=["POST"])
def generate():
upload_form = UploadForm()
if upload_form.validate_on_submit():
# fix make_cards
# pass some sort of condition to render_template to sort out the frame
# render
pass
return render_template("index.html", upload_form=upload_form)