mirror of
https://github.com/senju1337/senju.git
synced 2025-12-23 23:39:27 +00:00
feat: redirect /haiku to /haiku/<latest-id>
Refs: OPS-25
This commit is contained in:
parent
588cbeb001
commit
44ad774ada
2 changed files with 49 additions and 21 deletions
|
|
@ -1,16 +1,45 @@
|
|||
from flask import Flask, render_template
|
||||
from logging import Logger
|
||||
from pathlib import Path
|
||||
from flask import Flask, redirect, render_template, url_for
|
||||
|
||||
from senju.haiku import Haiku
|
||||
from senju.store_manager import StoreManager
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
store = StoreManager(Path("/tmp/store.db"))
|
||||
|
||||
testh = Haiku("hello world this is a haiku (not)")
|
||||
some_uuid = store.save_haiku(testh)
|
||||
|
||||
|
||||
@app.route("/")
|
||||
def index_view():
|
||||
return render_template("index.html", title="Senju")
|
||||
|
||||
|
||||
@app.route("/haiku")
|
||||
def haiku_view():
|
||||
@app.route("/haiku/")
|
||||
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))
|
||||
|
||||
|
||||
@app.route("/haiku/<int:haiku_id>")
|
||||
def haiku_view(haiku_id):
|
||||
logger = Logger(__name__)
|
||||
logger.debug(haiku_id)
|
||||
haiku: Haiku | None = store.load_haiku(haiku_id)
|
||||
if haiku is None:
|
||||
# TODO: add "haiku not found" page
|
||||
raise KeyError("haiku not found")
|
||||
context: dict = {
|
||||
"haiku": haiku
|
||||
}
|
||||
|
||||
return render_template(
|
||||
"haiku.html",
|
||||
"haiku.jinja",
|
||||
context=context,
|
||||
title="Haiku of the Day")
|
||||
|
|
|
|||
|
|
@ -25,24 +25,23 @@
|
|||
<div class="hidden md:block">
|
||||
<div class="ml-10 flex items-baseline space-x-4">
|
||||
<!-- Current: "bg-gray-900 text-white", Default: "text-gray-300 hover:bg-gray-700 hover:text-white" -->
|
||||
<a href="{{ url_for('index_view') }}"
|
||||
class="rounded-md px-3 py-2 text-sm font-medium
|
||||
{% if request.endpoint == 'index_view' %} bg-gray-900 text-white {% else %} text-gray-300 hover:bg-gray-700 hover:text-white {% endif %}"
|
||||
>
|
||||
Start
|
||||
</a>
|
||||
<a href="{{ url_for('index_view') }}"
|
||||
class="rounded-md px-3 py-2 text-sm font-medium
|
||||
{% if request.endpoint == 'index_view' %} bg-gray-900 text-white {% else %} text-gray-300 hover:bg-gray-700 hover:text-white {% endif %}">
|
||||
Start
|
||||
</a>
|
||||
|
||||
<a href="{{ url_for('haiku_view') }}"
|
||||
class="rounded-md px-3 py-2 text-sm font-mediRefs: OPS-11um
|
||||
{% if request.endpoint == 'haiku_view' %} bg-gray-900 text-white {% else %} text-gray-300 hover:bg-gray-700 hover:text-white {% endif %}"
|
||||
>
|
||||
Haiku
|
||||
</a>
|
||||
<a href="{{ url_for('haiku_index_view') }}"
|
||||
class="rounded-md px-3 py-2 text-sm font-mediRefs: OPS-11um
|
||||
{% if request.endpoint == 'haiku_view' %} bg-gray-900 text-white {% else %} text-gray-300 hover:bg-gray-700 hover:text-white {% endif %}">
|
||||
Haiku
|
||||
</a>
|
||||
|
||||
<a href="#"
|
||||
class="rounded-md px-3 py-2 text-sm font-medium text-gray-300 hover:bg-gray-700 hover:text-white">
|
||||
Information
|
||||
</a> </div>
|
||||
<a href="#"
|
||||
class="rounded-md px-3 py-2 text-sm font-medium text-gray-300 hover:bg-gray-700 hover:text-white">
|
||||
Information
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="hidden md:block">
|
||||
|
|
@ -125,7 +124,7 @@
|
|||
</div>
|
||||
</nav>
|
||||
|
||||
<header class="bg-violet-500 shadow-sm flex flex-row items-stretch gap-6
|
||||
<header class="bg-violet-500 shadow-sm flex flex-row items-stretch gap-6
|
||||
px-6 py-3">
|
||||
<div class="flex-1 place-self-center">
|
||||
<h1 class="text-3xl font-bold tracking-tight text-gray-900">{{ title }}</h1>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue