changed times of activities

This commit is contained in:
Tiago Scholten 2026-11-12 19:55:21 +01:00
parent b72842dda7
commit 43ee692609
3 changed files with 33 additions and 4 deletions

View File

@ -4,7 +4,7 @@ from pydantic import model_validator
from datetime import datetime
from .communication import CommunicationModel
from .submodels import ActivityPaymentInfo
from .submodels import ActivityPaymentInfo, Occurrence
from .enums import CommunicationCategory
from fiber_package.refs import SignupRefList
@ -16,14 +16,17 @@ from fiber_package.signup.element.form_base_question import FormBaseQuestion
from fiber_package.signup.element.types import FormElementUnion, FormTextUnion
# An activity = communication + slug + endtimes +
class ActivityModel(CommunicationModel):
category: Literal[CommunicationCategory.activity]
slug: str
# unique short name used in the public URL
start_time: datetime
end_time: datetime
# Every occurance is either a timeframe (start time - end time)
#
occurances: list[Occurrence] = Field(min_length=1)
payment_info: ActivityPaymentInfo | None = None

View File

@ -5,6 +5,5 @@ The category is only used to place the communication correctly in the weekly
mailing and the board-website, it is not visible (or relevant) to readers
'''
class CommunicationCategory(StrEnum):
announcement = "announcement"
news = "news"
activity = "activity"

View File

@ -12,3 +12,30 @@ class ActivityPaymentInfo(BaseModel):
] = None
class TimedOccurrence(BaseModel):
kind: Literal["timed"] = "timed"
start: datetime
end: datetime
@model_validator(mode="after")
def validate_interval(self):
if self.end <= self.start:
raise ValueError("End must be after start")
return self
class AllDayOccurrence(BaseModel):
kind: Literal["all_day"] = "all_day"
start_date: date
end_date: date # Exclusive!
@model_validator(mode="after")
def validate_interval(self):
if self.end_date <= self.start_date:
raise ValueError("End date must be after start date")
return self
Occurrence = TimedOccurrence | AllDayOccurrence