Add team registration and deletion
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -1,3 +1,16 @@
|
||||
{% macro teamEntries(event, work_type) -%}
|
||||
{% for entry in event.team | selectattr("work_type", "equalto", work_type)%}
|
||||
<div class="d-inline-flex align-items-center bg-light border rounded-pill px-3 py-1 m-1">
|
||||
<span class="me-2">{{ entry.person_name }}</span>
|
||||
<button type="button" class="btn btn-sm p-0 border-0 bg-transparent text-muted">
|
||||
<a href="/event/{{event.id}}/register_team/{{entry.id}}/delete">
|
||||
<i class="bi bi-trash"></i>
|
||||
</a>
|
||||
</button>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{%- endmacro %}
|
||||
|
||||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<p class="h1">{{ event.title }}</p>
|
||||
@@ -8,9 +21,12 @@
|
||||
<div class="row">
|
||||
<div class="col-md-4 d-flex justify-content-center align-items-center flex-column">
|
||||
<!-- Button trigger modal -->
|
||||
<button type="button" class="btn btn-primary mb-2" data-bs-toggle="modal" data-bs-target="#staticBackdrop">
|
||||
<button type="button" class="btn btn-primary mb-2" data-bs-toggle="modal" data-bs-target="#registration">
|
||||
Anmeldung hinzufügen
|
||||
</button>
|
||||
<button type="button" class="btn btn-primary mb-2" data-bs-toggle="modal" data-bs-target="#teamRegistration">
|
||||
Dienst übernehmen
|
||||
</button>
|
||||
{% if event.recipe_link %}
|
||||
<div class="mb-3">
|
||||
<a href="{{ event.recipe_link }}" class="btn btn-outline-primary" target="_blank">
|
||||
@@ -19,7 +35,40 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Dienste</h5>
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
Kochen: {% if event.team | selectattr("work_type", "equalto", "cooking") | list | count >= 3 %}✅{% endif %}
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
{{ teamEntries(event, "cooking") }}
|
||||
</div>
|
||||
</div>
|
||||
<hr/>
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
Spülen: {% if event.team | selectattr("work_type", "equalto", "dishes") | list | count >= 3 %}✅{% endif %}
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
{{ teamEntries(event, "dishes") }}
|
||||
</div>
|
||||
</div>
|
||||
<hr/>
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
Tische vorbereiten: {% if event.team | selectattr("work_type", "equalto", "tables") | list | count >= 1 %}✅{% endif %}
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
{{ teamEntries(event, "tables") }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">Zusammenfassung</h5>
|
||||
@@ -70,7 +119,7 @@
|
||||
</table>
|
||||
</div>
|
||||
<!-- Modal -->
|
||||
<div class="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1"
|
||||
<div class="modal fade" id="registration" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1"
|
||||
aria-labelledby="staticBackdropLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
@@ -119,5 +168,40 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Team Modal -->
|
||||
<div class="modal fade" id="teamRegistration" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1"
|
||||
aria-labelledby="teamRegistrationLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h1 class="modal-title fs-5" id="teamRegistrationLabel">Dienst übernehmen</h1>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<form action="/event/{{event.id}}/register_team" method="POST">
|
||||
<div class="modal-body">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<label for="personName" class="form-label">Name</label>
|
||||
<input name="personName" id="personName" type="text" class="form-control"
|
||||
aria-label="Name">
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label for="workType" class="form-label">Dienst-Art</label>
|
||||
<select id="workType" name="workType" class="form-select" aria-label="Multiple select example">
|
||||
<option value="cooking">Kochen</option>
|
||||
<option value="dishes">Spülen</option>
|
||||
<option value="tables">Tische vorbereiten</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" class="btn btn-primary">Anmelden</button>
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Abbrechen</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user