From 100fc2d7914b1e06270126aadaf0361a156fc709 Mon Sep 17 00:00:00 2001 From: Ed Date: Tue, 23 May 2023 21:02:44 +0200 Subject: [PATCH] Added karaoke function --- app.py | 3 ++- karaoke.py | 51 ++++++++++++++++++++++++++++++++++++++++ res/icons/microphone.svg | 1 + tpl/blocks/karaoke.html | 30 +++++++++++++++++++++++ tpl/welcome.html | 2 ++ 5 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 karaoke.py create mode 100644 res/icons/microphone.svg create mode 100644 tpl/blocks/karaoke.html diff --git a/app.py b/app.py index eac9b4d..7eb2785 100644 --- a/app.py +++ b/app.py @@ -19,12 +19,13 @@ app.ext.add_dependency(Quotas, get_quotas) from room import bp as room_bp from propic import bp as propic_bp +from karaoke import bp as karaoke_bp from export import bp as export_bp from stats import bp as stats_bp from api import bp as api_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) async def clear_session(request, exception): diff --git a/karaoke.py b/karaoke.py new file mode 100644 index 0000000..7b8cf21 --- /dev/null +++ b/karaoke.py @@ -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/") +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") + diff --git a/res/icons/microphone.svg b/res/icons/microphone.svg new file mode 100644 index 0000000..a987a20 --- /dev/null +++ b/res/icons/microphone.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tpl/blocks/karaoke.html b/tpl/blocks/karaoke.html new file mode 100644 index 0000000..8cea36f --- /dev/null +++ b/tpl/blocks/karaoke.html @@ -0,0 +1,30 @@ +
+ Karaoke & Contest +

Singing is the spirit of Karaoke! If you like doing it join us for some fun with your favourite songs!
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!

+

Participate in the contest!

+

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.

+ {% if order.karaoke_songs %} +

Your requests

+ + + + + + + {% for song, data in order.karaoke_songs.items() %} + + + + + + {% endfor %} +
Song nameStatus
{% if data['contest'] %}🎵{% else %}🏆{% endif %} {{song}}{% if data['approved'] %}Approved{% elif data['approved'] is none %}Pending{% else %}Rejected{% endif %}{% if data['approved'] is none %}Delete{% endif %}
+ {% endif %} + +

Request a new song

+
+ + + +
+
diff --git a/tpl/welcome.html b/tpl/welcome.html index cbe6adf..b0ff984 100644 --- a/tpl/welcome.html +++ b/tpl/welcome.html @@ -76,6 +76,8 @@ Nose count + {% include 'blocks/karaoke.html' %} +
Carpooling

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.