Work that has already been maxed will not show up in the dropdown
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import typing
|
||||
from datetime import datetime
|
||||
from typing import Literal
|
||||
|
||||
from sqlmodel import Field, Relationship, SQLModel, String
|
||||
|
||||
WorkTypes = typing.Literal["cooking", "dishes", "tables"]
|
||||
|
||||
|
||||
class Event(SQLModel, table=True):
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
@@ -19,20 +21,45 @@ class Event(SQLModel, table=True):
|
||||
team_dishes_min: int = 3
|
||||
team_dishes_max: int = 5
|
||||
|
||||
# Todo: Rename to "table"
|
||||
team_prep_min: int = 1
|
||||
team_prep_max: int = 1
|
||||
|
||||
registrations: list["Registration"] = Relationship()
|
||||
team: list["TeamRegistration"] = Relationship()
|
||||
|
||||
def team_min_reached(self, work_type: WorkTypes):
|
||||
threshold = {
|
||||
"cooking": self.team_cooking_min,
|
||||
"dishes": self.team_dishes_min,
|
||||
"tables": self.team_prep_min,
|
||||
}[work_type]
|
||||
return sum(1 for t in self.team if t.work_type == work_type) >= threshold
|
||||
|
||||
def team_max_reached(self, work_type: WorkTypes):
|
||||
threshold = {
|
||||
"cooking": self.team_cooking_max,
|
||||
"dishes": self.team_dishes_max,
|
||||
"tables": self.team_prep_max,
|
||||
}[work_type]
|
||||
return sum(1 for t in self.team if t.work_type == work_type) >= threshold
|
||||
|
||||
def all_teams_min(self):
|
||||
return all(
|
||||
self.team_min_reached(work_type) for work_type in typing.get_args(WorkTypes)
|
||||
)
|
||||
|
||||
def all_teams_max(self):
|
||||
return all(
|
||||
self.team_max_reached(work_type) for work_type in typing.get_args(WorkTypes)
|
||||
)
|
||||
|
||||
|
||||
class TeamRegistration(SQLModel, table=True):
|
||||
id: int | None = Field(default=None, primary_key=True)
|
||||
event_id: int | None = Field(default=None, foreign_key="event.id")
|
||||
person_name: str = Field(nullable=False)
|
||||
work_type: Literal["cooking", "dishes", "tables"] = Field(
|
||||
nullable=False, sa_type=String
|
||||
)
|
||||
work_type: WorkTypes = Field(nullable=False, sa_type=String)
|
||||
comment: str | None
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user