generated from bisco/codex-bootstrap
feat: add email confirmation and QR generation
This commit is contained in:
29
backend/bookings/qr.py
Normal file
29
backend/bookings/qr.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import base64
|
||||
from io import BytesIO
|
||||
|
||||
import qrcode
|
||||
|
||||
from .models import Reservation
|
||||
|
||||
|
||||
CHECK_IN_PREVIEW_PATH = "/api/check-ins/preview/"
|
||||
|
||||
|
||||
def build_check_in_preview_url(raw_check_in_token):
|
||||
return f"{CHECK_IN_PREVIEW_PATH}?token={raw_check_in_token}"
|
||||
|
||||
|
||||
def generate_check_in_qr_png(raw_check_in_token):
|
||||
qr_image = qrcode.make(build_check_in_preview_url(raw_check_in_token))
|
||||
buffer = BytesIO()
|
||||
qr_image.save(buffer, format="PNG")
|
||||
return buffer.getvalue()
|
||||
|
||||
|
||||
def generate_check_in_qr_base64(*, reservation, raw_check_in_token):
|
||||
if reservation.status != Reservation.Status.CONFIRMED:
|
||||
raise ValueError("QR codes are available only for confirmed reservations.")
|
||||
|
||||
png_bytes = generate_check_in_qr_png(raw_check_in_token)
|
||||
encoded = base64.b64encode(png_bytes).decode("ascii")
|
||||
return f"data:image/png;base64,{encoded}"
|
||||
Reference in New Issue
Block a user