64 lines
1.7 KiB
Python
64 lines
1.7 KiB
Python
from flask import Flask, render_template, request, redirect
|
|
from flask_sqlalchemy import SQLAlchemy
|
|
from model import *
|
|
from database_utils import reload_static_data, export_dynamic_data
|
|
|
|
app = Flask(__name__)
|
|
|
|
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///formula10.db"
|
|
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
|
|
|
|
db.init_app(app)
|
|
|
|
|
|
@app.route("/")
|
|
def index():
|
|
reload_static_data(db)
|
|
|
|
return render_template("index.jinja")
|
|
|
|
|
|
@app.route("/seasons/")
|
|
def default_season():
|
|
return redirect("/seasons/2023/p10")
|
|
|
|
|
|
@app.route("/seasons/<year>/")
|
|
def default_statistic(year):
|
|
return redirect("/seasons/" + year + "/p10")
|
|
|
|
|
|
@app.route("/seasons/<year>/<statistic>/")
|
|
def seasons(year, statistic):
|
|
seasons = db.session.execute(db.select(Season)).all() # For season selector
|
|
|
|
# @todo
|
|
races = db.session.execute(db.select(Race).where(Race.year==year)).all()
|
|
print(races[0].raceId)
|
|
|
|
# results = dict()
|
|
# for race in races:
|
|
# results[race.raceId] = db.session.execute(db.select(Result).filter_by(raceId=race.raceId)).all()
|
|
|
|
# return render_template(
|
|
# "season.jinja", year=year, statistic=statistic, seasons=seasons, races=races, results=results
|
|
# )
|
|
|
|
|
|
# @app.route("/teams", methods=["GET", "POST"])
|
|
# def teams():
|
|
# if request.method == "POST":
|
|
# new_team = Team(
|
|
# name = request.form["name"],
|
|
# country_code = request.form["country_code"]
|
|
# )
|
|
# print(new_team.name, new_team.country_code)
|
|
# db.session.add(new_team)
|
|
# db.session.commit()
|
|
#
|
|
# return render_template("teams.jinja", page="teams")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app.run(debug=False)
|