generated from bisco/codex-bootstrap
feat: add email confirmation and QR generation
This commit is contained in:
@@ -7,7 +7,9 @@ from django.utils import timezone
|
||||
|
||||
from shows.models import Performance
|
||||
|
||||
from .emailing import send_confirmation_email
|
||||
from .models import Reservation, ReservationToken
|
||||
from .qr import build_check_in_preview_url, generate_check_in_qr_base64
|
||||
|
||||
|
||||
CONFIRMATION_TOKEN_TTL = timedelta(hours=48)
|
||||
@@ -53,6 +55,8 @@ class ConfirmedReservationResult:
|
||||
check_in_token: ReservationToken
|
||||
raw_check_in_token: str
|
||||
available_seats: int
|
||||
qr_code_image: str
|
||||
qr_code_url: str
|
||||
|
||||
|
||||
def calculate_available_seats(performance):
|
||||
@@ -98,12 +102,17 @@ def create_pending_reservation(
|
||||
expires_at=confirmation_expires_at,
|
||||
)
|
||||
|
||||
return PendingReservationResult(
|
||||
result = PendingReservationResult(
|
||||
reservation=reservation,
|
||||
confirmation_token=confirmation_token,
|
||||
raw_confirmation_token=raw_confirmation_token,
|
||||
available_seats=available_seats,
|
||||
)
|
||||
send_confirmation_email(
|
||||
reservation=result.reservation,
|
||||
raw_confirmation_token=result.raw_confirmation_token,
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
def generate_confirmation_token(reservation, *, expires_at=None):
|
||||
@@ -173,6 +182,11 @@ def confirm_reservation_from_token(raw_token):
|
||||
check_in_token=check_in_token,
|
||||
raw_check_in_token=raw_check_in_token,
|
||||
available_seats=available_seats - reservation.party_size,
|
||||
qr_code_image=generate_check_in_qr_base64(
|
||||
reservation=reservation,
|
||||
raw_check_in_token=raw_check_in_token,
|
||||
),
|
||||
qr_code_url=build_check_in_preview_url(raw_check_in_token),
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user