Skip to content

Commit 1620e27

Browse files
committed
jump to form or submission after post
1 parent ff5f07c commit 1620e27

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](https://semver.org/)
66

7+
## [1.3.0] 2026-03-09
8+
9+
### Added
10+
11+
- after valid submission: jump to submission box
12+
- after invalid submission: jump to form
13+
14+
715
## [1.2.0] 2026-03-09
816

917
### Changed

simon_aksw_org/messages.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,13 @@ def get_messages(data_dir: Path) -> list[Message]:
3636
return messages
3737

3838

39-
def save_message(name: str, text: str, data_dir: Path) -> None:
40-
"""Strip html from message text and save it to data directory"""
39+
def save_message(name: str, text: str, data_dir: Path) -> str:
40+
"""Strip html from message text and save it to data directory
41+
42+
returns the ID of the message
43+
"""
4144
soup = BeautifulSoup(text, "html.parser")
4245
message = Message(name=name, message=soup.get_text())
4346
file_path = data_dir / f"{message.id!s}.json"
4447
file_path.write_text(message.model_dump_json(indent=2))
48+
return str(message.id)

simon_aksw_org/routers/home.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import httpx
66
from fastapi import APIRouter, Form
77
from starlette.requests import Request
8-
from starlette.responses import HTMLResponse
8+
from starlette.responses import HTMLResponse, RedirectResponse, Response
99

1010
from simon_aksw_org.messages import get_messages, save_message
1111
from simon_aksw_org.recaptcha import ResponseToken
@@ -47,22 +47,21 @@ async def submit_statement(
4747
name: Annotated[str, Form()],
4848
message: Annotated[str, Form()],
4949
g_recaptcha_response: Annotated[str, Form(alias="g-recaptcha-response")] = "",
50-
) -> HTMLResponse:
50+
) -> Response:
5151
"""Process condolence form submission"""
5252
settings = get_settings()
5353
settings.logger.info(f"{name} submitted a message ... captcha: {g_recaptcha_response}")
54-
context = PageContext(settings)
5554
response_token = ResponseToken(
5655
token=g_recaptcha_response, secret_key=settings.recaptcha_secret_key.get_secret_value()
5756
)
5857

5958
if await response_token.is_valid():
60-
save_message(name=name, text=message, data_dir=settings.data_dir)
61-
status_code = httpx.codes.CREATED
62-
else:
63-
context.error = "reCAPTCHA validation failed"
64-
status_code = httpx.codes.BAD_REQUEST
65-
59+
message_id = save_message(name=name, text=message, data_dir=settings.data_dir)
60+
context = PageContext(settings)
61+
return RedirectResponse(url=f"/#message-{message_id}", status_code=303)
62+
context = PageContext(settings)
63+
context.error = "reCAPTCHA validation failed"
64+
status_code = httpx.codes.BAD_REQUEST
6665
return settings.templates.TemplateResponse(
6766
request=request, name="home.html", context={"context": context}, status_code=status_code
6867
)

simon_aksw_org/templates/home.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ <h2>Unsere Anteilnahme</h2>
5353

5454
{% block form %}
5555
{% if context.allow_messages %}
56-
<div class="mt-5">
56+
<div class="mt-5" id="form">
5757
<h2 class="mb-4">Hinterlassen Sie eine Nachricht im Kondolenzbuch</h2>
5858
{% if context.error %}
5959
<div class="alert alert-danger" role="alert">{{ context.error }}</div>
6060
{% endif %}
61-
<form method="post">
61+
<form method="post" action="#form">
6262
<div class="mb-3">
6363
<label for="name" class="form-label">Name <span class="text-danger">*</span></label>
6464
<input type="text" class="form-control" id="name" name="name" required>

0 commit comments

Comments
 (0)