diff --git a/new-registration-app/main.py b/new-registration-app/main.py index a5228e8..9852b33 100644 --- a/new-registration-app/main.py +++ b/new-registration-app/main.py @@ -10,7 +10,7 @@ from fastapi.staticfiles import StaticFiles from fastapi.templating import Jinja2Templates from sqlmodel import Session, SQLModel, create_engine, select -from models import Event, Household, Registration +from models import Event, Household, Registration, TeamRegistration sqlite_file_name = "database.db" sqlite_url = f"sqlite:///{sqlite_file_name}" @@ -152,3 +152,38 @@ async def delete_registration( session.delete(session.exec(statement).one()) session.commit() return RedirectResponse(url=f"/event/{event_id}", status_code=status.HTTP_302_FOUND) + + +@app.post("/event/{event_id}/register_team") +async def add_team_registration(request: Request, event_id: int, session: SessionDep): + form_data = await request.form() + + person = form_data["personName"].strip() + work_type = form_data["workType"] + + statement = select(TeamRegistration).where( + TeamRegistration.person_name == person, TeamRegistration.work_type == work_type + ) + if session.exec(statement).one_or_none() is None: + registration = TeamRegistration( + person_name=person, + event_id=event_id, + work_type=form_data["workType"], + ) + TeamRegistration.model_validate(registration) + session.add(registration) + session.commit() + return RedirectResponse(url=f"/event/{event_id}", status_code=status.HTTP_302_FOUND) + + +@app.get("/event/{event_id}/register_team/{entry_id}/delete") +async def delete_team_registration( + request: Request, + event_id: int, + entry_id: int, + session: SessionDep, +): + statement = select(TeamRegistration).where(TeamRegistration.id == entry_id) + session.delete(session.exec(statement).one()) + session.commit() + return RedirectResponse(url=f"/event/{event_id}", status_code=status.HTTP_302_FOUND) diff --git a/new-registration-app/models.py b/new-registration-app/models.py index dc5c766..27c5927 100644 --- a/new-registration-app/models.py +++ b/new-registration-app/models.py @@ -1,6 +1,7 @@ from datetime import datetime +from typing import Literal -from sqlmodel import Field, Relationship, SQLModel +from sqlmodel import Field, Relationship, SQLModel, String class Event(SQLModel, table=True): @@ -11,7 +12,28 @@ class Event(SQLModel, table=True): description: str recipe_link: str + # Min and max number of people needed for cooking, doing the dishes and preparing the tables + team_cooking_min: int = 3 + team_cooking_max: int = 5 + + team_dishes_min: int = 3 + team_dishes_max: int = 5 + + team_prep_min: int = 1 + team_prep_max: int = 1 + registrations: list["Registration"] = Relationship() + team: list["TeamRegistration"] = Relationship() + + +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 + ) + comment: str | None class Household(SQLModel, table=True): diff --git a/new-registration-app/templates/event.html b/new-registration-app/templates/event.html index a51eebe..cb03742 100644 --- a/new-registration-app/templates/event.html +++ b/new-registration-app/templates/event.html @@ -1,3 +1,16 @@ +{% macro teamEntries(event, work_type) -%} + {% for entry in event.team | selectattr("work_type", "equalto", work_type)%} +
+ {{ entry.person_name }} + +
+ {% endfor %} +{%- endmacro %} + {% extends "base.html" %} {% block content %}

{{ event.title }}

@@ -8,9 +21,12 @@
- + {% if event.recipe_link %} {% endif %}
-
+
+
+
+
Dienste
+
+
+ Kochen: {% if event.team | selectattr("work_type", "equalto", "cooking") | list | count >= 3 %}✅{% endif %} +
+
+ {{ teamEntries(event, "cooking") }} +
+
+
+
+
+ Spülen: {% if event.team | selectattr("work_type", "equalto", "dishes") | list | count >= 3 %}✅{% endif %} +
+
+ {{ teamEntries(event, "dishes") }} +
+
+
+
+
+ Tische vorbereiten: {% if event.team | selectattr("work_type", "equalto", "tables") | list | count >= 1 %}✅{% endif %} +
+
+ {{ teamEntries(event, "tables") }} +
+
+
+
+
+
Zusammenfassung
@@ -70,7 +119,7 @@
-