From aaf5ab84eb155a0f76719a2d5253272c5053d247 Mon Sep 17 00:00:00 2001 From: cyfraeviolae Date: Wed, 3 Apr 2024 12:16:26 -0400 Subject: removing --- app.py | 32 +++++++++++++++++++++++++++++++- static/styles.css | 9 +++++++++ templates/event.html | 14 ++++++++++---- 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/app.py b/app.py index e7e44f2..b7a0516 100644 --- a/app.py +++ b/app.py @@ -33,7 +33,6 @@ from litestar.datastructures import State import ics -# TODO admin remove attendees # use url_fors, timezones? # error handling, auth errors, sql errors, input validation @@ -180,6 +179,34 @@ async def edit(state: State, request: Request, iden: str, password: str, data: A return Redirect(path="/symposium/event/" + iden + "?password=" + event.password) +@dataclass +class RemoveRequest: + name: str + +@post("/event/{iden:str}/remove") +async def remove(state: State, request: Request, iden: str, data: Annotated[RemoveRequest, Body(media_type=RequestEncodingType.URL_ENCODED)], password: str = "") -> Redirect: #-> Template: + async with sessionmaker(bind=state.engine) as session: + async with session.begin(): + query = select(Event).where(Event.iden == iden) + result = await session.execute(query) + event = result.scalar_one() + + manage = False + if password and hmac.compare_digest(event.password, password): + manage = True + if not manage: + raise ValueError("no auth") + + name = data.name + invites = json.loads(event.invites) + if name in invites: + invites.remove(name) + event.invites = json.dumps(invites) + url = "/symposium/event/" + iden + if password: + url += "?password=" + password + return Redirect(path=url) + @dataclass class JoinRequest: name: str @@ -193,6 +220,8 @@ async def join(state: State, request: Request, iden: str, data: Annotated[JoinRe event = result.scalar_one() name = data.name invites = json.loads(event.invites) + if name in invites: + raise ValueError("already exists") invites.append(name) event.invites = json.dumps(invites) url = "/symposium/event/" + iden @@ -207,6 +236,7 @@ app = Litestar( calendar, create, edit, + remove, join, create_static_files_router(path='/static', directories=['static']), ], diff --git a/static/styles.css b/static/styles.css index cce5d61..d0f3e5e 100644 --- a/static/styles.css +++ b/static/styles.css @@ -32,3 +32,12 @@ input { .when { width: fit-content; } + +.remove { + margin-left: 1.5em; + display: inline; +} + +.join-input { + width: 40%; +} diff --git a/templates/event.html b/templates/event.html index 687d696..925a707 100644 --- a/templates/event.html +++ b/templates/event.html @@ -34,8 +34,8 @@

{% endif %} -
{% if manage %} + Title: {% else %} @@ -81,12 +81,18 @@

- {% endif %}
+ {% endif %} Who?
{% for name in event.get_invites() %} - — {{ name }} + — {{ name }} + {% if manage %} +
+ + +
+ {% endif %}
{% endfor %} {% if manage %} @@ -94,7 +100,7 @@ {% else %}
{% endif %} - +
-- cgit v1.2.3