add db backend
This commit is contained in:
53
app.py
53
app.py
@@ -6,33 +6,24 @@ import magic
|
||||
import random
|
||||
import string
|
||||
|
||||
rechenreihen = {
|
||||
"1multi": [ "1 · 1", "2 · 1", "3 · 1", "4 · 1", "5 · 1", "6 · 1", "7 · 1", "8 · 1", "9 · 1", "10 · 1", "1 · 2", "1 · 3", "1 · 4", "1 · 5", "1 · 6", "1 · 7", "1 · 8", "1 · 9", "1 · 10" ],
|
||||
"2multi": [ "1 · 2", "2 · 2", "3 · 2", "4 · 2", "5 · 2", "6 · 2", "7 · 2", "8 · 2", "9 · 2", "10 · 2", "2 · 1", "2 · 3", "2 · 4", "2 · 5", "2 · 6", "2 · 7", "2 · 8", "2 · 9", "2 · 10" ],
|
||||
"3multi": [ "1 · 3", "2 · 3", "3 · 3", "4 · 3", "5 · 3", "6 · 3", "7 · 3", "8 · 3", "9 · 3", "10 · 3", "3 · 1", "3 · 2", "3 · 4", "3 · 5", "3 · 6", "3 · 7", "3 · 8", "3 · 9", "3 · 10" ],
|
||||
"4multi": [ "1 · 4", "2 · 4", "3 · 4", "4 · 4", "5 · 4", "6 · 4", "7 · 4", "8 · 4", "9 · 4", "10 · 4", "4 · 1", "4 · 2", "4 · 3", "4 · 5", "4 · 6", "4 · 7", "4 · 8", "4 · 9", "4 · 10" ],
|
||||
"5multi": [ "1 · 5", "2 · 5", "3 · 5", "4 · 5", "5 · 5", "6 · 5", "7 · 5", "8 · 5", "9 · 5", "10 · 5", "5 · 1", "5 · 2", "5 · 3", "5 · 4", "5 · 6", "5 · 7", "5 · 8", "5 · 9", "5 · 10" ],
|
||||
"6multi": [ "1 · 6", "2 · 6", "3 · 6", "4 · 6", "5 · 6", "6 · 6", "7 · 6", "8 · 6", "9 · 6", "10 · 6", "6 · 1", "6 · 2", "6 · 3", "6 · 4", "6 · 5", "6 · 7", "6 · 8", "6 · 9", "6 · 10" ],
|
||||
"7multi": [ "1 · 7", "2 · 7", "3 · 7", "4 · 7", "5 · 7", "6 · 7", "7 · 7", "8 · 7", "9 · 7", "10 · 7", "7 · 1", "7 · 2", "7 · 3", "7 · 4", "7 · 5", "7 · 6", "7 · 8", "7 · 9", "7 · 10" ],
|
||||
"8multi": [ "1 · 8", "2 · 8", "3 · 8", "4 · 8", "5 · 8", "6 · 8", "7 · 8", "8 · 8", "9 · 8", "10 · 8", "8 · 1", "8 · 2", "8 · 3", "8 · 4", "8 · 5", "8 · 6", "8 · 7", "8 · 9", "8 · 10" ],
|
||||
"9multi": [ "1 · 9", "2 · 9", "3 · 9", "4 · 9", "5 · 9", "6 · 9", "7 · 9", "8 · 9", "9 · 9", "10 · 9", "9 · 1", "9 · 2", "9 · 3", "9 · 4", "9 · 5", "9 · 6", "9 · 7", "9 · 8", "9 · 10" ],
|
||||
"10multi": [ "1 · 10", "2 · 10", "3 · 10", "4 · 10", "5 · 10", "6 · 10", "7 · 10", "8 · 10", "9 · 10", "10 · 10", "10 · 1", "10 · 2", "10 · 3", "10 · 4", "10 · 5", "10 · 6", "10 · 7", "10 · 8", "10 · 9" ],
|
||||
"Qmulti": [ "1 · 1", "2 · 2", "3 · 3", "4 · 4", "5 · 5", "6 · 6", "7 · 7", "8 · 8", "9 · 9", "10 · 10" ],
|
||||
"1div": [ "1 : 1", "2 : 1", "3 : 1", "4 : 1", "5 : 1", "6 : 1", "7 : 1", "8 : 1", "9 : 1", "10 : 1"],
|
||||
"2div": [ "2 : 2", "4 : 2", "6 : 2", "8 : 2", "10 : 2", "12 : 2", "14 : 2", "16 : 2", "18 : 2", "20 : 2" ],
|
||||
"3div": [ "3 : 3", "6 : 3", "9 : 3", "12 : 3", "15 : 3", "18 : 3", "21 : 3", "24 : 3", "27 : 3", "30 : 3" ],
|
||||
"4div": [ "4 : 4", "8 : 4", "12 : 4", "16 : 4", "20 : 4", "24 : 4", "28 : 4", "32 : 4", "36 : 4", "40 : 4" ],
|
||||
"5div": [ "5 : 5", "10 : 5", "15 : 5", "20 : 5", "25 : 5", "30 : 5", "35 : 5", "40 : 5", "45 : 5", "50 : 5" ],
|
||||
"6div": [ "6 : 6", "12 : 6", "18 : 6", "24 : 6", "30 : 6", "36 : 6", "42 : 6", "48 : 6", "54 : 6", "60 : 6" ],
|
||||
"7div": [ "7 : 7", "14 : 7", "21 : 7", "28 : 7", "35 : 7", "42 : 7", "49 : 7", "56 : 7", "63 : 7", "70 : 7" ],
|
||||
"8div": [ "8 : 8", "16 : 8", "24 : 8", "32 : 8", "40 : 8", "48 : 8", "56 : 8", "64 : 8", "72 : 8", "80 : 8" ],
|
||||
"9div": [ "9 : 9", "18 : 9", "27 : 9", "36 : 9", "45 : 9", "54 : 9", "63 : 9", "72 : 9", "81 : 9", "90 : 9" ],
|
||||
"10div": [ "10 : 10", "20 : 10", "30 : 10", "40 : 10", "50 : 10", "60 : 10", "70 : 10", "80 : 10", "90 : 10", "100 : 10" ],
|
||||
}
|
||||
|
||||
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_TRACK_MODIFICATIONS'] = False
|
||||
db = SQLAlchemy(app)
|
||||
|
||||
class rt_rechenreihen(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||
name = db.Column(db.String(200), nullable=False)
|
||||
typ = db.Column(db.String(1), nullable=False)
|
||||
|
||||
class rt_reihe(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||
set = db.Column(db.Integer, db.ForeignKey('rt_rechenreihen.id'), nullable=False)
|
||||
a = db.Column(db.Integer, nullable=False)
|
||||
b = db.Column(db.Integer, nullable=False)
|
||||
t = db.relationship("rt_rechenreihen")
|
||||
|
||||
@app.context_processor
|
||||
def get_date():
|
||||
@@ -45,8 +36,8 @@ def index():
|
||||
alle = []
|
||||
zufall = []
|
||||
for r in request.form.getlist('rechenreihen'):
|
||||
alle.extend(rechenreihen[r])
|
||||
|
||||
alle.extend(rt_reihe.query.filter_by(set = r).all())
|
||||
|
||||
if request.form.get('anzahl'):
|
||||
count = (int(request.form.get('anzahl')) + 1)
|
||||
else:
|
||||
@@ -55,10 +46,16 @@ def index():
|
||||
for i in range(1,count):
|
||||
if len(alle) == 0:
|
||||
break
|
||||
zufall.append(alle.pop(random.randint(0,len(alle)-1)))
|
||||
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))
|
||||
term.c += ' + ' if random.randint(0,1) else ' - '
|
||||
term.c += str(random.randint(1,maxValue))
|
||||
zufall.append(term)
|
||||
return render_template('arbeitsblatt.html',aufgaben=zufall)
|
||||
else:
|
||||
return render_template('generator.html')
|
||||
return render_template('generator.html', reihen=rt_rechenreihen)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user