Create a karaoke admin dashboard to manage songs

This commit is contained in:
Ed 2023-05-26 00:59:48 +02:00
parent d56945798e
commit ac94f9bc6d
2 changed files with 90 additions and 1 deletions

View File

@ -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/<songname>")
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!")

59
tpl/karaoke_admin.html Normal file
View File

@ -0,0 +1,59 @@
{% extends "base.html" %}
{% block title %}Furizon 2023 Karaoke Admin{% endblock %}
{% block main %}
<main class="container">
<h1>Karaoke Admin</h1>
<h2>Canzoni da cantare</h2>
<table>
{% for s in songs if s.approved is not none and (not s.singed) %}
<tr {% if s.approved == false %}style="text-decoration: line-through"{% endif %}>
<td>{{'🏆' if s.contest else '🎵'}}</td>
<td>{{s.order.code}} ({{s.order.name}})</td>
<td>{{s.song}}</td>
<td><a role="button" href="/manage/karaoke/sing/{{s.order.code}}{{s.song|urlencode}}">Canta</a></td>
</tr>
{% endfor %}
</table>
<h2>Canzoni da approvare</h2>
<form method="post" action="approve">
<table>
{% for s in songs if s.approved is none %}
<tr>
<td>{{'🏆' if s.contest else '🎵'}}</td>
<td>{{s.order.code}} ({{s.order.name}})</td>
<td>{{s.song}}</td>
<td style="width:4em"><input type="radio" name="{{s.order.code}}{{s.song}}" style="background:#090;" value="yes"> <input type="radio" style="background:#900;" name="{{s.order.code}}{{s.song}}" value="no"></td>
</tr>
{% endfor %}
</table>
<div class="grid">
<input type="reset" value="Reset" />
<input type="submit" value="Approva/Disapprova" />
</div>
</form>
<h2>Canzoni cantate</h2>
<table>
{% for s in songs if s.singed %}
<tr>
<td>{{'🏆' if s.contest else '🎵'}}</td>
<td>{{s.order.code}} ({{s.order.name}})</td>
<td>{{s.song}}</td>
</tr>
{% endfor %}
</table>
<h2>Canzoni disapprovate</h2>
<table>
{% for s in songs if s.approved == false %}
<tr>
<td>{{'🏆' if s.contest else '🎵'}}</td>
<td>{{s.order.code}} ({{s.order.name}})</td>
<td>{{s.song}}</td>
</tr>
{% endfor %}
</table>
</main>
{% endblock %}