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:
@@ -56,6 +56,9 @@ class EventSchema(ModelSchema):
|
||||
absolute_featured_image_url: Optional[str] = None
|
||||
absolute_featured_image_thumbnail_url: Optional[str] = None
|
||||
absolute_featured_image_preview_url: Optional[str] = None
|
||||
status: str
|
||||
status_label: str
|
||||
effective_registration_end_date: datetime
|
||||
|
||||
class Meta:
|
||||
model = Event
|
||||
@@ -63,7 +66,8 @@ class EventSchema(ModelSchema):
|
||||
'id', 'title', 'slug', 'description', 'featured_image', 'event_type',
|
||||
'address', 'location', 'online_link', 'start_time', 'end_time',
|
||||
'registration_start_date', 'registration_end_date', 'registration_success_markdown',
|
||||
'capacity', 'price', 'status', 'created_at', 'updated_at'
|
||||
'capacity', 'price', 'is_published',
|
||||
'is_cancelled', 'created_at', 'updated_at'
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
@@ -87,6 +91,8 @@ class EventSchema(ModelSchema):
|
||||
|
||||
@staticmethod
|
||||
def resolve_registration_count(obj):
|
||||
if hasattr(obj, "browse_registration_count"):
|
||||
return obj.browse_registration_count
|
||||
now = timezone.now()
|
||||
return obj.registrations.filter(is_deleted=False).filter(
|
||||
Q(status__in=[Registration.StatusChoices.CONFIRMED, Registration.StatusChoices.ATTENDED])
|
||||
@@ -113,9 +119,13 @@ class EventListSchema(Schema):
|
||||
end_time: datetime
|
||||
registration_start_date: Optional[datetime] = None
|
||||
registration_end_date: Optional[datetime] = None
|
||||
effective_registration_end_date: datetime
|
||||
capacity: Optional[int] = None
|
||||
price: Optional[float] = None
|
||||
status: str
|
||||
status_label: str
|
||||
is_published: bool
|
||||
is_cancelled: bool
|
||||
registration_count: int
|
||||
created_at: datetime
|
||||
|
||||
@@ -172,7 +182,8 @@ class EventCreateSchema(Schema):
|
||||
registration_end_date: Optional[datetime] = None
|
||||
capacity: Optional[int] = None
|
||||
price: Optional[float] = None
|
||||
status: str = "draft"
|
||||
is_published: bool = False
|
||||
is_cancelled: bool = False
|
||||
registration_success_markdown: Optional[str] = None
|
||||
gallery_image_ids: Optional[List[int]] = []
|
||||
|
||||
@@ -191,7 +202,8 @@ class EventUpdateSchema(Schema):
|
||||
registration_end_date: Optional[datetime] = None
|
||||
capacity: Optional[int] = None
|
||||
price: Optional[float] = None
|
||||
status: Optional[str] = None
|
||||
is_published: Optional[bool] = None
|
||||
is_cancelled: Optional[bool] = None
|
||||
registration_success_markdown: Optional[str] = None
|
||||
gallery_image_ids: Optional[List[int]] = None
|
||||
|
||||
@@ -344,6 +356,17 @@ class EventBriefSchema(Schema):
|
||||
slug: str
|
||||
start_date: datetime
|
||||
end_date: Optional[datetime] = None
|
||||
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_published: bool = True
|
||||
is_cancelled: bool = False
|
||||
location: Optional[str] = None
|
||||
price: int
|
||||
absolute_image_url: Optional[str] = None
|
||||
@@ -398,9 +421,13 @@ class RegistrationHubEventOut(Schema):
|
||||
end_time: datetime
|
||||
registration_start_date: Optional[datetime] = None
|
||||
registration_end_date: Optional[datetime] = None
|
||||
effective_registration_end_date: datetime
|
||||
capacity: Optional[int] = None
|
||||
price: int
|
||||
status: str
|
||||
status_label: str
|
||||
is_published: bool
|
||||
is_cancelled: bool
|
||||
registration_count: int
|
||||
image_url: Optional[str] = None
|
||||
registration_success_markdown: Optional[str] = None
|
||||
|
||||
Reference in New Issue
Block a user