From 3c4d31e1b9466c8b427e4e140f50ac19ebb32baa Mon Sep 17 00:00:00 2001 From: Ed Date: Tue, 4 Jul 2023 23:06:48 +0200 Subject: [PATCH] Added helper functions to checkin (admin only) --- checkin.py | 72 ++++++++++++++++++++++++++++++++++++++++++++++ tpl/checkin_1.html | 49 +++++++++++++++++++++++++++++++ tpl/checkin_2.html | 56 ++++++++++++++++++++++++++++++++++++ tpl/checkin_3.html | 19 ++++++++++++ 4 files changed, 196 insertions(+) create mode 100644 checkin.py create mode 100644 tpl/checkin_1.html create mode 100644 tpl/checkin_2.html create mode 100644 tpl/checkin_3.html diff --git a/checkin.py b/checkin.py new file mode 100644 index 0000000..03904d1 --- /dev/null +++ b/checkin.py @@ -0,0 +1,72 @@ +from sanic.response import html, redirect, text +from sanic import Blueprint, exceptions, response +from random import choice +from ext import * +from config import headers, base_url +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("checkin", url_prefix="/checkin") + +@bp.get("/") +async def redirect_start(request): + return response.redirect("start") + +@bp.get("/start") +async def start_checkin(request): + orders = request.app.ctx.om.cache.values() + tpl = request.app.ctx.tpl.get_template('checkin_1.html') + return html(tpl.render(orders=orders)) + +@bp.get("/order") +async def show_order(request): + + max_id = 0 + for o in request.app.ctx.om.cache.values(): + if not o.badge_id: continue + max_id = max(o.badge_id, max_id) + + order = await request.app.ctx.om.get_order(code=request.args.get('order')) + + if order.room_id == order.code: + room_owner = order + else: + room_owner = await request.app.ctx.om.get_order(code=order.room_id) + + tpl = request.app.ctx.tpl.get_template('checkin_2.html') + return html(tpl.render(order=order, room_owner=room_owner, max_id=max_id)) + +@bp.post("/checkin") +async def do_checkin(request): + + # Update room info + order = await request.app.ctx.om.get_order(code=request.form.get('code')) + if order.room_id == order.code: + room_owner = order + await order.edit_answer('actual_room', request.form.get('actual_room')) + else: + room_owner = await request.app.ctx.om.get_order(code=order.room_id) + await room_owner.edit_answer('actual_room', request.form.get('actual_room')) + await room_owner.send_answers() + + roommates = [await request.app.ctx.om.get_order(code=code, cached=True) for code in room_owner.room_members] + + # Update nfc and badge id + await order.edit_answer('nfc_id', request.form.get('nfc_id')) + await order.edit_answer('badge_id', request.form.get('badge_id')) + await order.send_answers() + + if not order.checked_in: + async with httpx.AsyncClient() as client: + res = await client.post(base_url.replace('events/beyond/', 'checkinrpc/redeem/'), json={'secret': order.barcode, 'source_type': 'barcode', 'type': 'entry', 'lists': [3,]}, headers=headers) + + tpl = request.app.ctx.tpl.get_template('checkin_3.html') + return html(tpl.render(order=order, room_owner=room_owner, roommates=roommates)) + + diff --git a/tpl/checkin_1.html b/tpl/checkin_1.html new file mode 100644 index 0000000..9f5e868 --- /dev/null +++ b/tpl/checkin_1.html @@ -0,0 +1,49 @@ +{% extends "base.html" %} +{% block main %} +
+

Cerca ordine

+ +
+ + +
+ +
+{% endblock %} diff --git a/tpl/checkin_2.html b/tpl/checkin_2.html new file mode 100644 index 0000000..dfe1aa7 --- /dev/null +++ b/tpl/checkin_2.html @@ -0,0 +1,56 @@ +{% extends "base.html" %} +{% block main %} +
+

{{order.code}} {{order.name}} ({{order.first_name}} {{order.last_name}})

+

Commento: {{order.comment or '--'}}
+ Note ordine: {{order.notes or '--'}}
+ Stato ordine: {{order.status}}
+ Sponsor: {{order.sponsorship}}
+ Compagni di stanza: {% for code in room_owner.room_members %}{{code}} {% endfor %}
+ Apri su pretix

+
+ + + + + + + + +
+ +
+{% endblock %} diff --git a/tpl/checkin_3.html b/tpl/checkin_3.html new file mode 100644 index 0000000..3fee8ec --- /dev/null +++ b/tpl/checkin_3.html @@ -0,0 +1,19 @@ +{% extends "base.html" %} +{% block main %} +
+

✅ Checkin effettuato!

+

Ricorda di apporre il numero sul badge! Numero: {{order.badge_id}}

+ +

Altri membri della stessa stanza ({{room_owner.actual_room}})

+ + {% for o in roommates %} + + + + + + {% endfor %} +
{{o.code}}{{o.name}}{{'Effettua Checkin' if not o.checked_in else '✅'}}
+

Effettua un altro checkin ➡️

+
+{% endblock %}