diff --git a/app/crud.py b/app/crud.py index d0a9e0c..639552b 100644 --- a/app/crud.py +++ b/app/crud.py @@ -2,6 +2,7 @@ import app.models as models from sqlalchemy.orm.attributes import flag_modified from sqlalchemy.sql import text +import pickle def get_songs_and_vote_for_session(db, session_name) -> list[models.Song]: session_entry = activate_session(db, session_name) @@ -21,6 +22,7 @@ def get_all_songs_and_votes(db) -> list: songs.aca_artist, songs.title, songs.url, + songs.categories, COUNT(vote) FILTER (where vote = -1) as "nein" , COUNT(vote) FILTER (where vote = 0) as "neutral", COUNT(vote) FILTER (where vote = 1) as "ja" @@ -28,7 +30,17 @@ def get_all_songs_and_votes(db) -> list: GROUP BY song_id ORDER BY song_id """)).fetchall() - return [dict(r._mapping) for r in res] + def process_row(r): + e = dict(r._mapping) + c = pickle.loads(e["categories"]) + c = {k : bool(v) for k, v in c.items()} + e["categories"] = c + + return e + + res = [process_row(r) for r in res] + + return res def create_song(db,