diff --git a/formula10/__init__.py b/formula10/__init__.py index 03469b3..e6ab84a 100644 --- a/formula10/__init__.py +++ b/formula10/__init__.py @@ -1,6 +1,13 @@ +import os from flask import Flask from flask_sqlalchemy import SQLAlchemy +# Load local ENV variables (can be set when calling the executable) +ENABLE_TIMING: bool = False if os.getenv("DISABLE_TIMING") == "True" else True +print("Running Formula10 with:") +if not ENABLE_TIMING: + print("- Disabled timing constraints") + app: Flask = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite:///formula10.db" app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False @@ -24,10 +31,6 @@ import formula10.controller.error_controller # TODO -# General - -# Create a model baseclass that contains the cached teams/drivers/races etc., so the points + template model can be derived from it - # Statistics # - Auto calculate points # - Display points somewhere in race table? Below the name in the table header. @@ -35,6 +38,10 @@ import formula10.controller.error_controller # - Generate static diagram using chart.js + templating the js (funny yikes) # - Which driver was voted most for dnf? +# General +# - Decouple names from IDs + Fix Valtteri/Russel spelling errors +# - Unit testing (as much as possible, but especially points calculation) + # Possible but probably not # - Show cards of previous race results, like with season guesses? # - Make user order changeable using drag'n'drop? \ No newline at end of file diff --git a/formula10/database/update_queries.py b/formula10/database/update_queries.py index 6bbfef9..9ccb85e 100644 --- a/formula10/database/update_queries.py +++ b/formula10/database/update_queries.py @@ -11,7 +11,7 @@ from formula10.database.model.db_race_result import DbRaceResult from formula10.database.model.db_season_guess import DbSeasonGuess from formula10.database.model.db_user import DbUser from formula10.database.validation import any_is_none, positions_are_contiguous, race_has_started -from formula10 import db +from formula10 import ENABLE_TIMING, db def find_or_create_race_guess(user_name: str, race_name: str) -> DbRaceGuess: @@ -37,7 +37,7 @@ def update_race_guess(race_name: str, user_name: str, pxx_select: str | None, dn if any_is_none(pxx_select, dnf_select): return error_redirect(f"Picks for race \"{race_name}\" were not saved, because you did not fill all the fields.") - if race_has_started(race_name=race_name): + if ENABLE_TIMING and race_has_started(race_name=race_name): return error_redirect(f"No picks for race \"{race_name}\" can be entered, as this race has already started.") if race_has_result(race_name): @@ -57,7 +57,7 @@ def update_race_guess(race_name: str, user_name: str, pxx_select: str | None, dn def delete_race_guess(race_name: str, user_name: str) -> Response: # Don't change guesses that are already over - if race_has_started(race_name=race_name): + if ENABLE_TIMING and race_has_started(race_name=race_name): return error_redirect(f"No picks for race \"{race_name}\" can be deleted, as this race has already started.") if race_has_result(race_name): @@ -92,7 +92,7 @@ def find_or_create_season_guess(user_name: str) -> DbSeasonGuess: def update_season_guess(user_name: str, guesses: List[str | None], team_winner_guesses: List[str | None], podium_driver_guesses: List[str]) -> Response: # Pylance marks type errors here, but those are intended. Columns are marked nullable. - if race_has_started(race_name="Bahrain"): + if ENABLE_TIMING and race_has_started(race_name="Bahrain"): return error_redirect("No season picks can be entered, as the season has already begun!") season_guess: DbSeasonGuess = find_or_create_season_guess(user_name) @@ -133,7 +133,7 @@ def find_or_create_race_result(race_name: str) -> DbRaceResult: def update_race_result(race_name: str, pxx_driver_names_list: List[str], first_dnf_driver_names_list: List[str], dnf_driver_names_list: List[str], excluded_driver_names_list: List[str]) -> Response: - if not race_has_started(race_name=race_name): + if ENABLE_TIMING and not race_has_started(race_name=race_name): return error_redirect("No race result can be entered, as the race has not begun!") # Use strings as keys, as these dicts will be serialized to json