mirror of
https://github.com/senju1337/senju.git
synced 2025-12-24 07:39:29 +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__)
|
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("/")
|
@app.route("/")
|
||||||
def index_view():
|
def index_view():
|
||||||
return render_template("index.html", title="Senju")
|
return render_template("index.html", title="Senju")
|
||||||
|
|
||||||
|
|
||||||
@app.route("/haiku")
|
@app.route("/haiku/")
|
||||||
def haiku_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))
|
||||||
|
|
||||||
|
|
||||||
|
@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(
|
return render_template(
|
||||||
"haiku.html",
|
"haiku.jinja",
|
||||||
|
context=context,
|
||||||
title="Haiku of the Day")
|
title="Haiku of the Day")
|
||||||
|
|
|
||||||
|
|
@ -27,22 +27,21 @@
|
||||||
<!-- Current: "bg-gray-900 text-white", Default: "text-gray-300 hover:bg-gray-700 hover:text-white" -->
|
<!-- Current: "bg-gray-900 text-white", Default: "text-gray-300 hover:bg-gray-700 hover:text-white" -->
|
||||||
<a href="{{ url_for('index_view') }}"
|
<a href="{{ url_for('index_view') }}"
|
||||||
class="rounded-md px-3 py-2 text-sm font-medium
|
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 %}"
|
{% if request.endpoint == 'index_view' %} bg-gray-900 text-white {% else %} text-gray-300 hover:bg-gray-700 hover:text-white {% endif %}">
|
||||||
>
|
|
||||||
Start
|
Start
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a href="{{ url_for('haiku_view') }}"
|
<a href="{{ url_for('haiku_index_view') }}"
|
||||||
class="rounded-md px-3 py-2 text-sm font-mediRefs: OPS-11um
|
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 %}"
|
{% if request.endpoint == 'haiku_view' %} bg-gray-900 text-white {% else %} text-gray-300 hover:bg-gray-700 hover:text-white {% endif %}">
|
||||||
>
|
|
||||||
Haiku
|
Haiku
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<a href="#"
|
<a href="#"
|
||||||
class="rounded-md px-3 py-2 text-sm font-medium text-gray-300 hover:bg-gray-700 hover:text-white">
|
class="rounded-md px-3 py-2 text-sm font-medium text-gray-300 hover:bg-gray-700 hover:text-white">
|
||||||
Information
|
Information
|
||||||
</a> </div>
|
</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="hidden md:block">
|
<div class="hidden md:block">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue