latin/main.py

47 lines
1.7 KiB
Python
Raw Normal View History

2020-10-15 23:33:52 +02:00
from flask import Flask
from flask import render_template
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import func
from flask_wtf import FlaskForm
from wtforms import Form, RadioField, SubmitField, HiddenField
app = Flask(__name__)
app.config["SECRET_KEY"] = "asdasfgrwee"
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///latin.sqlite"
db = SQLAlchemy(app)
class Word(db.Model):
id = db.Column(db.Integer, primary_key=True)
dictionarium = db.Column(db.String, unique=True, nullable=False)
coniugatio = db.Column(db.Integer, unique=False, nullable=False)
def __repr__(self):
return '%r; %d conjugation' % (self.dictionarium, self.coniugatio)
class ConjugatioAnswer(FlaskForm):
radio = RadioField('', choices=[(1, 'Prima'), (2, 'Secunda'), (3, 'Tertia'), (4, 'Quarta')])
word = HiddenField()
submit = SubmitField('Check')
next_word = SubmitField('Next word')
@app.route('/latin')
def latin():
return render_template('latin.html')
@app.route('/latin/coniugationes')
def coniugationes():
return render_template('coniugationes.html')
@app.route('/latin/coniugationes/quod', methods=["GET", "POST"])
def coniugationes_test():
form = ConjugatioAnswer()
if form.validate_on_submit():
word = Word.query.filter_by(dictionarium=form.word.data).first()
if not form.next_word.data:
if int(form.radio.data) == word.coniugatio:
return render_template('coniugationes.html', dictionarium = word.dictionarium, form = form, success = True)
return render_template('coniugationes.html', dictionarium = word.dictionarium, form = form, fail = True)
word = Word.query.order_by(func.random()).first()
form.word.data = word.dictionarium
return render_template('coniugationes.html', dictionarium = word.dictionarium, form = form)