Added karaoke function

This commit is contained in:
Ed 2023-05-23 21:02:44 +02:00
parent 39cf1b6b4e
commit 100fc2d791
5 changed files with 86 additions and 1 deletions

3
app.py
View File

@ -19,12 +19,13 @@ app.ext.add_dependency(Quotas, get_quotas)
from room import bp as room_bp from room import bp as room_bp
from propic import bp as propic_bp from propic import bp as propic_bp
from karaoke import bp as karaoke_bp
from export import bp as export_bp from export import bp as export_bp
from stats import bp as stats_bp from stats import bp as stats_bp
from api import bp as api_bp from api import bp as api_bp
from carpooling import bp as carpooling_bp from carpooling import bp as carpooling_bp
app.blueprint([room_bp, propic_bp, export_bp, stats_bp, api_bp, carpooling_bp]) app.blueprint([room_bp, karaoke_bp, propic_bp, export_bp, stats_bp, api_bp, carpooling_bp])
@app.exception(exceptions.SanicException) @app.exception(exceptions.SanicException)
async def clear_session(request, exception): async def clear_session(request, exception):

51
karaoke.py Normal file
View File

@ -0,0 +1,51 @@
from sanic.response import html, redirect, text
from sanic import Blueprint, exceptions
from random import choice
from ext import *
from config import headers, PROPIC_DEADLINE
from PIL import Image
from os.path import isfile
from os import unlink
from io import BytesIO
from hashlib import sha224
from time import time
from urllib.parse import unquote
import json
bp = Blueprint("karaoke", url_prefix="/manage/karaoke")
@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!")
song = request.form.get('song')
if not song:
raise exceptions.BadRequest("This song is not valid!")
karaoke_songs = order.karaoke_songs or {}
if song not in karaoke_songs:
karaoke_songs[song[:64]] = {'approved': None, 'ts': time(), 'contest': bool(request.form.get('wants_contest'))}
await order.edit_answer('karaoke_songs', json.dumps(karaoke_songs))
await order.send_answers()
return redirect("/manage/welcome#karaoke")
@bp.get("/delete/<songname>")
async def del_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!")
karaoke_songs = order.karaoke_songs or {}
songname = unquote(songname)
if not songname in karaoke_songs:
raise exceptions.BadRequest(f"The song you're trying to delete {songname} does not exist in your list of songs.")
del karaoke_songs[songname]
await order.edit_answer('karaoke_songs', json.dumps(karaoke_songs))
await order.send_answers()
return redirect("/manage/welcome#karaoke")

1
res/icons/microphone.svg Normal file
View File

@ -0,0 +1 @@
<?xml version="1.0" ?><svg data-name="Layer 1" id="Layer_1" viewBox="0 0 64 64" xmlns="http://www.w3.org/2000/svg"><path d="M49.35,14.65A11.86,11.86,0,1,0,41,34.9a11.86,11.86,0,0,0,8.39-20.25Z"/><path d="M25.4,26.13l-12,15.15a4.19,4.19,0,0,0,.32,5.58l.28.28-2.27,2.27a2,2,0,1,0,2.83,2.83L16.86,50l.28.28a4.2,4.2,0,0,0,5.58.32l15.15-12A15.92,15.92,0,0,1,25.4,26.13Z"/></svg>

After

Width:  |  Height:  |  Size: 373 B

30
tpl/blocks/karaoke.html Normal file
View File

@ -0,0 +1,30 @@
<details id="karaoke">
<summary role="button"><img src="/res/icons/microphone.svg" class="icon" />Karaoke & Contest</summary>
<p>Singing is the spirit of Karaoke! If you like doing it join us for some fun with your favourite songs!<br />You can still just come to the desk and ask for a song, but keep in mind we will always give priority to requests that came through the form. Also, special matters or difficult to find songs will only be honored by the form!</p>
<h3>Participate in the contest!</h3>
<p>You can either decide to just sing, or let others vote you (anonymously) and try to win the prize! If you wish to send a song for the contest, make sure to toggle the appropriate option.</p>
{% if order.karaoke_songs %}
<h2>Your requests</h2>
<table>
<tr>
<th>Song name</th>
<th>Status</th>
<th style="width:1%;"></th>
</tr>
{% for song, data in order.karaoke_songs.items() %}
<tr>
<td>{% if data['contest'] %}🎵{% else %}🏆{% endif %} {{song}}</td>
<td>{% if data['approved'] %}<span style="color:#090;">Approved</span>{% elif data['approved'] is none %}<span style="color:#990;">Pending</span>{% else %}<span style="color:#900;">Rejected</span>{% endif %}</td>
<td>{% if data['approved'] is none %}<a role="button" href="karaoke/delete/{{song|urlencode}}">Delete</a>{% endif %}</td>
</tr>
{% endfor %}
</table>
{% endif %}
<h3>Request a new song</h3>
<form method="POST" action="karaoke/add">
<input type="text" name="song" placeholder="Insert Artist - Title here..." />
<label style="margin-bottom:2em;" for="switch"><input type="checkbox" name="wants_contest" role="switch"> I want to partecipate in the contest</label>
<input type="submit" value="Submit" />
</form>
</details>

View File

@ -76,6 +76,8 @@
<a href="/manage/nosecount" role="button">Nose count</a> <a href="/manage/nosecount" role="button">Nose count</a>
</details> </details>
{% include 'blocks/karaoke.html' %}
<details id="carpooling"> <details id="carpooling">
<summary role="button"><img src="/res/icons/car.svg" class="icon" />Carpooling</summary> <summary role="button"><img src="/res/icons/car.svg" class="icon" />Carpooling</summary>
<p>We want to make it easy for attendees to find and offer carpooling options. If you have seats available in your car, you can use our carpooling system to offer rides to other attendees. And if you need a ride, you can search for leftover seats in cars that are already heading to the convention. This is a great way to save money on gas and reduce your carbon footprint, while also getting to know other attendees and making new friends.</p> <p>We want to make it easy for attendees to find and offer carpooling options. If you have seats available in your car, you can use our carpooling system to offer rides to other attendees. And if you need a ride, you can search for leftover seats in cars that are already heading to the convention. This is a great way to save money on gas and reduce your carbon footprint, while also getting to know other attendees and making new friends.</p>