Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5ba472db42 |
14
app/crud.py
14
app/crud.py
@@ -2,6 +2,7 @@ import app.models as models
|
|||||||
from sqlalchemy.orm.attributes import flag_modified
|
from sqlalchemy.orm.attributes import flag_modified
|
||||||
|
|
||||||
from sqlalchemy.sql import text
|
from sqlalchemy.sql import text
|
||||||
|
import pickle
|
||||||
|
|
||||||
def get_songs_and_vote_for_session(db, session_name) -> list[models.Song]:
|
def get_songs_and_vote_for_session(db, session_name) -> list[models.Song]:
|
||||||
session_entry = activate_session(db, session_name)
|
session_entry = activate_session(db, session_name)
|
||||||
@@ -21,6 +22,7 @@ def get_all_songs_and_votes(db) -> list:
|
|||||||
songs.aca_artist,
|
songs.aca_artist,
|
||||||
songs.title,
|
songs.title,
|
||||||
songs.url,
|
songs.url,
|
||||||
|
songs.categories,
|
||||||
COUNT(vote) FILTER (where vote = -1) as "nein" ,
|
COUNT(vote) FILTER (where vote = -1) as "nein" ,
|
||||||
COUNT(vote) FILTER (where vote = 0) as "neutral",
|
COUNT(vote) FILTER (where vote = 0) as "neutral",
|
||||||
COUNT(vote) FILTER (where vote = 1) as "ja"
|
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
|
GROUP BY song_id ORDER BY song_id
|
||||||
""")).fetchall()
|
""")).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,
|
def create_song(db,
|
||||||
|
|||||||
Reference in New Issue
Block a user