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:
@@ -315,6 +315,15 @@ class PublicProfileEventSchema(Schema):
|
||||
title: str
|
||||
slug: str
|
||||
start_time: datetime
|
||||
end_time: datetime
|
||||
registration_start_date: Optional[datetime] = None
|
||||
registration_end_date: Optional[datetime] = None
|
||||
effective_registration_end_date: datetime
|
||||
capacity: Optional[int] = None
|
||||
registration_count: int = 0
|
||||
status: str
|
||||
status_label: str
|
||||
is_cancelled: bool = False
|
||||
image_url: Optional[str] = None
|
||||
participation: Literal["confirmed", "attended"]
|
||||
|
||||
|
||||
@@ -400,7 +400,7 @@ def get_public_profile(request, username: str):
|
||||
Registration.objects.filter(
|
||||
user=user,
|
||||
event__is_deleted=False,
|
||||
event__status__in=[Event.StatusChoices.PUBLISHED, Event.StatusChoices.COMPLETED],
|
||||
event__is_published=True,
|
||||
status__in=[Registration.StatusChoices.CONFIRMED, Registration.StatusChoices.ATTENDED],
|
||||
)
|
||||
.select_related("event")
|
||||
@@ -412,6 +412,15 @@ def get_public_profile(request, username: str):
|
||||
"title": event.title,
|
||||
"slug": event.slug,
|
||||
"start_time": event.start_time,
|
||||
"end_time": event.end_time,
|
||||
"registration_start_date": event.registration_start_date,
|
||||
"registration_end_date": event.registration_end_date,
|
||||
"effective_registration_end_date": event.effective_registration_end_date,
|
||||
"capacity": event.capacity,
|
||||
"registration_count": event.current_attendees_count,
|
||||
"status": event.status,
|
||||
"status_label": event.status_label,
|
||||
"is_cancelled": event.is_cancelled,
|
||||
"image_url": request.build_absolute_uri(event.featured_image.url) if event.featured_image else None,
|
||||
"participation": registration.status,
|
||||
})
|
||||
|
||||
@@ -92,7 +92,7 @@ def test_public_profile_hides_personal_fields_until_the_user_opts_in(client, use
|
||||
)
|
||||
event = event_factory(slug="public-profile-event")
|
||||
Registration.objects.create(event=event, user=member, status=Registration.StatusChoices.CONFIRMED)
|
||||
draft_event = event_factory(slug="private-profile-event", status=Event.StatusChoices.DRAFT)
|
||||
draft_event = event_factory(slug="private-profile-event", is_published=False)
|
||||
Registration.objects.create(event=draft_event, user=member, status=Registration.StatusChoices.ATTENDED)
|
||||
|
||||
public_path = f"/api/auth/public-profile/{member.username}"
|
||||
|
||||
Reference in New Issue
Block a user