This repository has been archived by the owner on Oct 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkin.py
73 lines (57 loc) · 2.34 KB
/
checkin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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_event
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
from metrics import *
import pretixClient
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:
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,]})
tpl = request.app.ctx.tpl.get_template('checkin_3.html')
return html(tpl.render(order=order, room_owner=room_owner, roommates=roommates))