Work that has already been maxed will not show up in the dropdown

This commit is contained in:
2025-10-07 20:42:41 +02:00
parent 4a470ae09e
commit 1d29e954b8
3 changed files with 39 additions and 11 deletions

View File

@@ -164,6 +164,7 @@ async def add_team_registration(request: Request, event_id: int, session: Sessio
statement = select(TeamRegistration).where( statement = select(TeamRegistration).where(
TeamRegistration.person_name == person, TeamRegistration.work_type == work_type TeamRegistration.person_name == person, TeamRegistration.work_type == work_type
) )
# if the person has already registered for the same work type, just ignore
if session.exec(statement).one_or_none() is None: if session.exec(statement).one_or_none() is None:
registration = TeamRegistration( registration = TeamRegistration(
person_name=person, person_name=person,

View File

@@ -1,8 +1,10 @@
import typing
from datetime import datetime from datetime import datetime
from typing import Literal
from sqlmodel import Field, Relationship, SQLModel, String from sqlmodel import Field, Relationship, SQLModel, String
WorkTypes = typing.Literal["cooking", "dishes", "tables"]
class Event(SQLModel, table=True): class Event(SQLModel, table=True):
id: int | None = Field(default=None, primary_key=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_min: int = 3
team_dishes_max: int = 5 team_dishes_max: int = 5
# Todo: Rename to "table"
team_prep_min: int = 1 team_prep_min: int = 1
team_prep_max: int = 1 team_prep_max: int = 1
registrations: list["Registration"] = Relationship() registrations: list["Registration"] = Relationship()
team: list["TeamRegistration"] = 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): class TeamRegistration(SQLModel, table=True):
id: int | None = Field(default=None, primary_key=True) id: int | None = Field(default=None, primary_key=True)
event_id: int | None = Field(default=None, foreign_key="event.id") event_id: int | None = Field(default=None, foreign_key="event.id")
person_name: str = Field(nullable=False) person_name: str = Field(nullable=False)
work_type: Literal["cooking", "dishes", "tables"] = Field( work_type: WorkTypes = Field(nullable=False, sa_type=String)
nullable=False, sa_type=String
)
comment: str | None comment: str | None

View File

@@ -24,7 +24,7 @@
<button type="button" class="btn btn-primary mb-2" data-bs-toggle="modal" data-bs-target="#registration"> <button type="button" class="btn btn-primary mb-2" data-bs-toggle="modal" data-bs-target="#registration">
Anmeldung hinzufügen Anmeldung hinzufügen
</button> </button>
<button type="button" class="btn btn-primary mb-2" data-bs-toggle="modal" data-bs-target="#teamRegistration"> <button type="button" class="btn btn-primary mb-2 {% if event.all_teams_max() %}disabled{% endif %}" data-bs-toggle="modal" data-bs-target="#teamRegistration">
Dienst übernehmen Dienst übernehmen
</button> </button>
{% if event.recipe_link %} {% if event.recipe_link %}
@@ -41,7 +41,7 @@
<h5 class="card-title">Dienste</h5> <h5 class="card-title">Dienste</h5>
<div class="row"> <div class="row">
<div class="col-md-4"> <div class="col-md-4">
Kochen: {% if event.team | selectattr("work_type", "equalto", "cooking") | list | count >= 3 %}✅{% endif %} Kochen: {% if event.team_min_reached("cooking") %}✅{% endif %}
</div> </div>
<div class="col-md-8"> <div class="col-md-8">
{{ teamEntries(event, "cooking") }} {{ teamEntries(event, "cooking") }}
@@ -50,7 +50,7 @@
<hr/> <hr/>
<div class="row"> <div class="row">
<div class="col-md-4"> <div class="col-md-4">
Spülen: {% if event.team | selectattr("work_type", "equalto", "dishes") | list | count >= 3 %}✅{% endif %} Spülen: {% if event.team_min_reached("dishes") %}✅{% endif %}
</div> </div>
<div class="col-md-8"> <div class="col-md-8">
{{ teamEntries(event, "dishes") }} {{ teamEntries(event, "dishes") }}
@@ -59,7 +59,7 @@
<hr/> <hr/>
<div class="row"> <div class="row">
<div class="col-md-4"> <div class="col-md-4">
Tische vorbereiten: {% if event.team | selectattr("work_type", "equalto", "tables") | list | count >= 1 %}✅{% endif %} Tische vorbereiten: {% if event.team_min_reached("tables") %}✅{% endif %}
</div> </div>
<div class="col-md-8"> <div class="col-md-8">
{{ teamEntries(event, "tables") }} {{ teamEntries(event, "tables") }}
@@ -188,9 +188,9 @@
<div class="col-md-6"> <div class="col-md-6">
<label for="workType" class="form-label">Dienst-Art</label> <label for="workType" class="form-label">Dienst-Art</label>
<select id="workType" name="workType" class="form-select" aria-label="Multiple select example"> <select id="workType" name="workType" class="form-select" aria-label="Multiple select example">
<option value="cooking">Kochen</option> {% if not event.team_max_reached("cooking") %}<option value="cooking">Kochen</option>{% endif %}
<option value="dishes">Spülen</option> {% if not event.team_max_reached("dishes") %}<option value="dishes">Spülen</option>{% endif %}
<option value="tables">Tische vorbereiten</option> {% if not event.team_max_reached("tables") %}<option value="tables">Tische vorbereiten</option>{% endif %}
</select> </select>
</div> </div>
</div> </div>