Corrections of SQL Alchemy error
This commit is contained in:
19
app/main.py
19
app/main.py
@@ -7,6 +7,7 @@ import os, json
|
||||
from datetime import datetime, timedelta
|
||||
from io import BytesIO
|
||||
from xhtml2pdf import pisa
|
||||
from sqlalchemy import text
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@@ -61,17 +62,17 @@ def load_user(user_id):
|
||||
# --- Hilfsfunktionen ---
|
||||
def get_calculated_schedule(car_num):
|
||||
config = RaceConfig.query.first()
|
||||
stints = Stint.query.filter_by(car_number=car_num).order_by(Stint.order).all()
|
||||
if not config: return []
|
||||
|
||||
stints = Stint.query.filter_by(car_number=car_num).order_by(Stint.order).all()
|
||||
schedule = []
|
||||
current_time = config.start_time
|
||||
fuel_capacity = 120.0 # Liter (Beispielhaft fixiert)
|
||||
fuel_capacity = 120.0
|
||||
|
||||
for i, stint in enumerate(stints):
|
||||
driver = stint.driver
|
||||
if not driver: continue
|
||||
|
||||
# Vereinfachte Berechnung: Ein Stint ist voll, wenn der Tank leer ist
|
||||
laps_possible = int(fuel_capacity / driver.cons_per_lap)
|
||||
duration_sec = laps_possible * driver.avg_lap_time
|
||||
|
||||
@@ -172,11 +173,21 @@ def logout():
|
||||
if __name__ == '__main__':
|
||||
with app.app_context():
|
||||
db.create_all()
|
||||
# Initialer User falls nicht vorhanden
|
||||
|
||||
# Manueller Fix: Spalte 'theme' hinzufügen, falls sie fehlt (SQLite-spezifisch)
|
||||
try:
|
||||
db.session.execute(text("ALTER TABLE user ADD COLUMN theme VARCHAR(20) DEFAULT 'light'"))
|
||||
db.session.commit()
|
||||
except Exception:
|
||||
# Fehler tritt auf, wenn Spalte bereits existiert – das ist ok
|
||||
db.session.rollback()
|
||||
|
||||
if not User.query.filter_by(username='mscaltenbach').first():
|
||||
pw = generate_password_hash('admin123')
|
||||
db.session.add(User(username='mscaltenbach', password=pw, theme='light'))
|
||||
|
||||
if not RaceConfig.query.first():
|
||||
db.session.add(RaceConfig())
|
||||
|
||||
db.session.commit()
|
||||
app.run(host='0.0.0.0', port=5000, debug=True)
|
||||
Reference in New Issue
Block a user