From ac94f9bc6dfcdb96010265fe96d8eeb2b73d354e Mon Sep 17 00:00:00 2001 From: Ed Date: Fri, 26 May 2023 00:59:48 +0200 Subject: [PATCH] Create a karaoke admin dashboard to manage songs --- karaoke.py | 32 ++++++++++++++++++++++- tpl/karaoke_admin.html | 59 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 tpl/karaoke_admin.html diff --git a/karaoke.py b/karaoke.py index 2553b32..ecf7627 100644 --- a/karaoke.py +++ b/karaoke.py @@ -1,5 +1,5 @@ from sanic.response import html, redirect, text -from sanic import Blueprint, exceptions +from sanic import Blueprint, exceptions, response from random import choice from ext import * from config import headers, PROPIC_DEADLINE @@ -32,6 +32,36 @@ async def show_songs(request, order: Order): tpl = request.app.ctx.tpl.get_template('karaoke_admin.html') return html(tpl.render(songs=songs)) +@bp.post("/approve") +async def approve_songs(request, order: Order): + + if order.code not in ['9YKGJ', 'CMPQG']: + raise exceptions.Forbidden("Birichino") + + for song in request.form: + o = await request.app.ctx.om.get_order(code=song[:5]) + o.karaoke_songs[song[5:]]['approved'] = request.form[song][0] == 'yes' + await order.edit_answer('karaoke_songs', json.dumps(o.karaoke_songs)) + await order.send_answers() + + return response.redirect('/manage/karaoke/admin') + +@bp.get("/sing/") +async def sing_song(request, order: Order, songname): + + if not order: raise exceptions.Forbidden("You have been logged out. Please access the link in your E-Mail to login again!") + + if order.code not in ['9YKGJ', 'CMPQG']: + raise exceptions.Forbidden("Birichino") + + songname = unquote(songname) + o = await request.app.ctx.om.get_order(code=songname[:5]) + o.karaoke_songs[songname[5:]]['singed'] = True + await order.edit_answer('karaoke_songs', json.dumps(o.karaoke_songs)) + await order.send_answers() + + return redirect("/manage/karaoke/admin") + @bp.post("/add") async def add_song(request, order: Order): if not order: raise exceptions.Forbidden("You have been logged out. Please access the link in your E-Mail to login again!") diff --git a/tpl/karaoke_admin.html b/tpl/karaoke_admin.html new file mode 100644 index 0000000..41a3eb2 --- /dev/null +++ b/tpl/karaoke_admin.html @@ -0,0 +1,59 @@ +{% extends "base.html" %} +{% block title %}Furizon 2023 Karaoke Admin{% endblock %} +{% block main %} +
+

Karaoke Admin

+ +

Canzoni da cantare

+ + {% for s in songs if s.approved is not none and (not s.singed) %} + + + + + + + {% endfor %} +
{{'🏆' if s.contest else '🎵'}}{{s.order.code}} ({{s.order.name}}){{s.song}}Canta
+ +

Canzoni da approvare

+
+ + {% for s in songs if s.approved is none %} + + + + + + + {% endfor %} +
{{'🏆' if s.contest else '🎵'}}{{s.order.code}} ({{s.order.name}}){{s.song}}
+
+ + +
+
+ +

Canzoni cantate

+ + {% for s in songs if s.singed %} + + + + + + {% endfor %} +
{{'🏆' if s.contest else '🎵'}}{{s.order.code}} ({{s.order.name}}){{s.song}}
+ +

Canzoni disapprovate

+ + {% for s in songs if s.approved == false %} + + + + + + {% endfor %} +
{{'🏆' if s.contest else '🎵'}}{{s.order.code}} ({{s.order.name}}){{s.song}}
+
+{% endblock %}