feat: display the default haiku in the frontend with a small note

Refs: OPS-65
This commit is contained in:
Christoph J. Scherr 2025-03-23 14:26:54 +01:00
parent 8f3ccb94d1
commit da52e643a7
No known key found for this signature in database
GPG key ID: 9EB784BB202BB7BB
2 changed files with 11 additions and 8 deletions

View file

@ -24,20 +24,18 @@ def index_view():
def haiku_index_view():
haiku_id: int | None = store.get_id_of_latest_haiku()
if haiku_id is None:
# TODO: add "empty haiku list" error page
raise KeyError("no haiku exist yet")
return redirect(url_for("haiku_view", haiku_id=haiku_id))
haiku_id = 0
return redirect(url_for("haiku_view", haiku_id=haiku_id, is_default=1))
@app.route("/haiku/<int:haiku_id>")
def haiku_view(haiku_id):
"""test"""
haiku: Haiku | None = store.load_haiku(haiku_id)
if haiku is None:
# TODO: add "haiku not found" page
raise KeyError("haiku not found")
is_default: bool = request.args.get("is_default") == "1"
haiku: Haiku = store.load_haiku(haiku_id)
context: dict = {
"haiku": haiku
"haiku": haiku,
"is_default": is_default
}
return render_template(

View file

@ -11,6 +11,11 @@
{% endfor %}
</p>
</div>
{% if context.is_default %}
<div class="mb-5">
<b>Note:</b> No haikus have been found in the haiku store.
</div>
{% endif %}
<a href="{{ url_for('index_view') }}"
class=" inline-block bg-violet-600 hover:bg-violet-700 text-white font-bold py-2 px-4 rounded-lg">
Back to Home