feat: derive event lifecycle status from dates and flags
Replace persisted event statuses with publication and cancellation flags, and compute public lifecycle labels from event timing and registration capacity. Keep filters, registration checks, and profile responses aligned with the derived status.
This commit is contained in:
@@ -367,7 +367,7 @@ def create_payment(request, payload: CreatePaymentIn):
|
||||
pk=payload.event_id,
|
||||
is_deleted=False,
|
||||
)
|
||||
if event.status == Event.StatusChoices.CANCELLED:
|
||||
if event.is_cancelled:
|
||||
raise HttpError(400, "این رویداد لغو شده است و امکان پرداخت ندارد.")
|
||||
|
||||
keyed_payment = Payment.objects.filter(
|
||||
@@ -440,14 +440,8 @@ def create_payment(request, payload: CreatePaymentIn):
|
||||
|
||||
needs_new_checkout = not registration or registration.status == Registration.StatusChoices.CANCELLED
|
||||
if needs_new_checkout:
|
||||
if event.status != Event.StatusChoices.PUBLISHED:
|
||||
if event.get_display_status(now=now) != "registration_open":
|
||||
raise HttpError(400, "ثبتنام این رویداد فعال نیست.")
|
||||
if event.registration_start_date and event.registration_start_date > now:
|
||||
raise HttpError(400, "زمان ثبتنام هنوز آغاز نشده است")
|
||||
if event.registration_end_date and event.registration_end_date < now:
|
||||
raise HttpError(400, "مهلت ثبتنام به پایان رسیدهاست")
|
||||
if not event.has_available_slots:
|
||||
raise HttpError(400, "ظرفیت شرکتکنندگان تکمیل است")
|
||||
if not registration or registration.status == Registration.StatusChoices.CANCELLED:
|
||||
registration = Registration.objects.create(
|
||||
event=event,
|
||||
@@ -604,7 +598,7 @@ def create_payment(request, payload: CreatePaymentIn):
|
||||
if (
|
||||
registration is not None
|
||||
and registration.status == Registration.StatusChoices.CANCELLED
|
||||
) or event.status == Event.StatusChoices.CANCELLED:
|
||||
) or event.is_cancelled:
|
||||
if registration is not None:
|
||||
queue_checkout_reconciliation(registration)
|
||||
|
||||
@@ -653,7 +647,7 @@ def _checkout_may_be_confirmed(event, registration, paid_at, now):
|
||||
Registration.StatusChoices.ATTENDED,
|
||||
):
|
||||
return True
|
||||
if event.status == Event.StatusChoices.CANCELLED:
|
||||
if event.is_cancelled:
|
||||
return False
|
||||
|
||||
expiry = registration.checkout_expires_at
|
||||
@@ -736,7 +730,7 @@ def _mark_payment_paid(payment_id: int, verification_data: dict | None = None):
|
||||
|
||||
now = timezone.now()
|
||||
if registration and registration.status == Registration.StatusChoices.PENDING:
|
||||
if event.status == Event.StatusChoices.CANCELLED:
|
||||
if event.is_cancelled:
|
||||
registration.status = Registration.StatusChoices.CANCELLED
|
||||
registration.cancellation_reason = Registration.CancellationReasonChoices.EVENT_CANCELLED
|
||||
registration.save(update_fields=["status", "cancellation_reason", "updated_at"])
|
||||
|
||||
Reference in New Issue
Block a user