Admin fix für unterschidliche Playlists

This commit is contained in:
mikka 2026-04-21 19:11:28 +02:00
parent f3d0f6bd7b
commit 1d906d4d5f
2 changed files with 19 additions and 17 deletions

34
app.py
View file

@ -87,16 +87,12 @@ def zeit(sekunden):
@app.route("/")
def hello_world():
liste = request.args.get("liste")
print("/")
print(liste)
if liste is None:
return redirect("/playlists")
print(liste)
with open(liste+".json","r") as f:
songs = json.load(f)
for song in songs:
kartenGeneriren(song)
print(songs)
gesamtLaenge = 0
for song in songs:
gesamtLaenge += song["laenge"]
@ -107,15 +103,11 @@ def hello_world():
def playlists():
listen = glob("*.json")
listen = (liste.replace(".json","") for liste in listen)
print("/playlists")
print(listen)
return render_template('playlists.html',lists=listen)
@app.route("/neueliste")
def neueliste():
name = request.args.get("name")
print("/neueliste")
print(name)
if name is not None:
with open(name +".json", "x") as f:
json.dump([],f)
@ -127,8 +119,6 @@ def neueliste():
def suche():
such = request.args.get("suche")
liste = request.args.get("liste")
print("/suche")
print(liste)
if such is not None:
ergebnisse = wikisuche(such)
else:
@ -143,22 +133,34 @@ def suche_finden():
song = {"wikiid":request.form.get("id")}
kartenGeneriren(song)
songs.append(song)
print(liste)
with open(liste+".json","w") as f:
json.dump(songs,f,indent=2,ensure_ascii=False)
return redirect("/suche?liste="+liste,303)
@app.route("/ADMIN")
@app.route("/rm")
def admin():
liste = request.args.get("liste")
if liste is None:
return redirect("/playlists")
with open(liste+".json","r") as f:
songs = json.load(f)
for song in songs:
kartenGeneriren(song)
gesamtLaenge = 0
for song in songs:
gesamtLaenge += song["laenge"]
return render_template('index.html', karten=songs,gesamtLaenge=gesamtLaenge,admin=True )
return render_template('index.html', karten=songs,gesamtLaenge=gesamtLaenge,liste=liste,admin=True)
@app.route("/ADMIN",methods=["POST"])
@app.route("/rm",methods=["POST"])
def loeschen():
liste = request.args.get("liste")
song = int(request.form.get("index"))
with open(liste+".json","r") as f:
print(liste+".json")
songs = json.load(f)
print(songs)
print(songs)
del songs[song]
with open("songs.json","w") as f:
with open(liste+".json","w") as f:
json.dump(songs,f,indent=2,ensure_ascii=False)
return redirect("/ADMIN",303)
return redirect("/rm?liste="+liste,303)