Finalize migration to SQLAlchemy.

This commit is contained in:
2019-10-16 22:37:22 +02:00
parent fccd75d6c5
commit eafcfffc1f
7 changed files with 158 additions and 148 deletions

View File

@@ -1,16 +1,16 @@
from estusshots import orm, models, db
from estusshots.orm import Season
from estusshots.orm import new_session, EventType, Season, Player, Drink, Enemy
def event_choices():
return [(member.value, member.name) for member in models.EventType]
return [(member.value, member.name) for member in EventType]
def season_choices():
""" Query the database for available seasons.
"""
Query the database for available seasons.
This returns a list of tuples with the season ID and a display string.
"""
db = orm.new_session()
db = new_session()
seasons = db.query(Season).order_by(Season.code).all()
choices = [(s.id, f"{s.code}: {s.game}") for s in seasons]
choices.insert(0, (-1, "No Season"))
@@ -21,8 +21,8 @@ def player_choice():
"""
Query database for a list of available players to bind them to a select box
"""
sql, args = db.load_players()
players = db.query_db(sql, args, cls=models.Player)
db = new_session()
players = sorted(db.query(Player).all(), key=lambda x: x.name)
return [(p.id, p.name) for p in players]
@@ -30,8 +30,8 @@ def drink_choice():
"""
Query database for a list of all available drinks to select from
"""
sql, args = db.load_drinks()
drinks = db.query_db(sql, args, cls=models.Drink)
db = new_session()
drinks = db.query(Drink).order_by(Drink.name).all()
choices = [(d.id, d.name) for d in drinks]
choices.insert(0, (-1, "None"))
return choices
@@ -41,9 +41,13 @@ def enemy_choice_for_season(season_id: int):
"""
Query database for all available enemies in this season
"""
sql, args = db.load_enemies_for_season(season_id)
enemies = db.query_db(sql, args, cls=models.Enemy)
return [(e.id, e.name) for e in enemies]
db = new_session()
season: Season = db.query(Season).get(season_id)
global_enemies = db.query(Enemy).filter(Enemy.season_id == -1).all()
if not season and not global_enemies:
return []
combined = global_enemies + season.enemies
return [(e.id, e.name) for e in combined]
class IterableBase: