feat: add dockerfile, update sqlalchemy, fix template

This commit is contained in:
2026-01-11 20:42:58 +01:00
parent 95c8a5f066
commit 1b681ed101
7 changed files with 116 additions and 66 deletions

70
app.py
View File

@@ -9,7 +9,7 @@ import string
app = Flask(__name__)
app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1, x_host=1)
app.secret_key = 'eng5iikeiwah3lae4idoo0woh4eiy6Th'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///homeschooling.db'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////app/homeschooling.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
@@ -30,42 +30,44 @@ def get_date():
date = datetime.now()
return { "now": date.strftime("%Y-%m-%d") }
@app.route('/', methods = ['GET', 'POST'])
@app.route('/', methods=['GET'])
def index():
if request.method == 'POST':
alle = []
zufall = []
for r in request.form.getlist('rechenreihen'):
alle.extend(rt_reihe.query.filter_by(set = r).all())
if request.form.get('anzahl'):
count = (int(request.form.get('anzahl')) + 1)
else:
count = len(alle)
reihen = db.session.execute(db.select(rt_rechenreihen).order_by(rt_rechenreihen.id)).scalars().all()
return render_template('generator.html', reihen=reihen)
while count > 1:
if len(alle) == 0:
break
term = alle.pop(random.randint(0,len(alle)-1))
term.c = ''
if request.form.get('gemischteAufgaben'):
maxValue = eval(str(term.a) + term.t.typ + str(term.b))
if random.randint(0,1):
term.c += ' + '
t = int(100 - maxValue)
maxValue = t
else:
term.c += ' - '
if maxValue <= 1:
alle.append(term)
continue
term.c += str(random.randint(1,maxValue))
zufall.append(term)
count -= 1
return render_template('arbeitsblatt.html',aufgaben=zufall,maxPerPage=int(request.form.get('maxPerPage')))
@app.route('/', methods=['POST'])
def index_post():
alle = []
zufall = []
for r in request.form.getlist('rechenreihen'):
alle.extend(db.session.execute(db.select(rt_reihe).filter_by(set=r)).scalars().all())
if request.form.get('anzahl'):
count = (int(request.form.get('anzahl')) + 1)
else:
return render_template('generator.html', reihen=rt_rechenreihen)
count = len(alle)
while count > 1:
if len(alle) == 0:
break
term = alle.pop(random.randint(0,len(alle)-1))
term.c = ''
if request.form.get('gemischteAufgaben'):
maxValue = eval(str(term.a) + term.t.typ + str(term.b))
if random.randint(0,1):
term.c += ' + '
t = int(100 - maxValue)
maxValue = t
else:
term.c += ' - '
if maxValue <= 1:
alle.append(term)
continue
term.c += str(random.randint(1,maxValue))
zufall.append(term)
count -= 1
return render_template('arbeitsblatt.html',aufgaben=zufall,maxPerPage=int(request.form.get('maxPerPage')))
if __name__ == "__main__":
app.run(debug=True)
app.run(debug=True)