2023-07-04 21:06:48 +00:00
|
|
|
from sanic.response import html, redirect, text
|
|
|
|
from sanic import Blueprint, exceptions, response
|
|
|
|
from random import choice
|
|
|
|
from ext import *
|
2023-12-30 10:27:42 +00:00
|
|
|
from config import headers, base_url_event
|
2023-07-04 21:06:48 +00:00
|
|
|
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
|
2024-02-14 19:22:56 +00:00
|
|
|
from metrics import *
|
2024-02-22 18:15:33 +00:00
|
|
|
import pretixClient
|
2023-07-04 21:06:48 +00:00
|
|
|
|
|
|
|
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:
|
2024-02-22 18:15:33 +00:00
|
|
|
await pretixClient.post("", baseUrl=base_url_event.replace(f'events/{EVENT_NAME}/', 'checkinrpc/redeem/'), json={'secret': order.barcode, 'source_type': 'barcode', 'type': 'entry', 'lists': [3,]})
|
2023-07-04 21:06:48 +00:00
|
|
|
|
|
|
|
tpl = request.app.ctx.tpl.get_template('checkin_3.html')
|
|
|
|
return html(tpl.render(order=order, room_owner=room_owner, roommates=roommates))
|
|
|
|
|
|
|
|
|