Add option for unordered/grouped view

This commit is contained in:
matthias@matsewe.de
2024-06-12 14:20:47 +02:00
parent 90dd150a1f
commit 70edc621cf

View File

@@ -55,50 +55,56 @@ async def root(request: Request) -> HTMLResponse:
@app.get("/vote") @app.get("/vote")
async def vote(request: Request, session_id: str, db: Session = Depends(get_db)) -> HTMLResponse: async def vote(request: Request, session_id: str, unordered: bool = False, db: Session = Depends(get_db)) -> HTMLResponse:
veto_mode = get_setting(db, "veto_mode") veto_mode = get_setting(db, "veto_mode")
songs = [Song(**s.__dict__, vote=v, vote_comment=c) songs = [Song(**s.__dict__, vote=v, vote_comment=c)
for s, v, c in get_songs_and_vote_for_session(db, session_id)] for s, v, c in get_songs_and_vote_for_session(db, session_id)]
songs_by_category = {} if unordered:
all_categories = set() songs_by_category = {"Alle Lieder" : songs}
all_categories = {"Alle Lieder"}
for song in songs:
all_categories.update(song.categories.keys())
else:
songs_by_category = {}
all_categories = set()
wildcard_songs = [] wildcard_songs = []
current_songs = [] current_songs = []
other_songs = [] other_songs = []
for song in songs: for song in songs:
if (not song.singable) and (not veto_mode): if (not song.singable) and (not veto_mode):
continue continue
if song.is_current: if song.is_current:
current_songs.append(song) current_songs.append(song)
continue continue
if not song.is_aca: if not song.is_aca:
wildcard_songs.append(song) wildcard_songs.append(song)
continue continue
if not song.main_category: if not song.main_category:
other_songs.append(song) other_songs.append(song)
continue continue
if song.main_category not in songs_by_category: if song.main_category not in songs_by_category:
songs_by_category[song.main_category] = [] songs_by_category[song.main_category] = []
songs_by_category[song.main_category].append(song) songs_by_category[song.main_category].append(song)
all_categories.update(song.categories.keys()) all_categories.update(song.categories.keys())
songs_by_category["Sonstige"] = other_songs songs_by_category["Sonstige"] = other_songs
songs_by_category["Wildcard (nicht a cappella)"] = wildcard_songs songs_by_category["Wildcard (nicht a cappella)"] = wildcard_songs
songs_by_category["Aktuelles Programm"] = current_songs songs_by_category["Aktuelles Programm"] = current_songs
all_categories = list(all_categories) all_categories = list(all_categories)
all_categories.sort() all_categories.sort()
all_categories.append("Sonstige") all_categories.append("Sonstige")
all_categories.append("Wildcard (nicht a cappella)") all_categories.append("Wildcard (nicht a cappella)")
all_categories.append("Aktuelles Programm") all_categories.append("Aktuelles Programm")
# print(all_categories) # print(all_categories)
# with open('/data/songs_by_cat.json', 'w') as f: # with open('/data/songs_by_cat.json', 'w') as f: