Show the date a link was added
The created_at timestamp was already stored but never displayed. Add a "datum" Jinja filter that converts the stored UTC value to local time and render it on both the link card and the edit form. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
13
app/main.py
13
app/main.py
@@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
from datetime import datetime, timezone
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from fastapi import Depends, FastAPI, Form, Request
|
from fastapi import Depends, FastAPI, Form, Request
|
||||||
@@ -26,6 +27,18 @@ templates.env.globals.update(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def format_datum(value: datetime | None) -> str:
|
||||||
|
"""Formatiere einen UTC-Zeitstempel als lokale Datums-/Zeitangabe."""
|
||||||
|
if not value:
|
||||||
|
return ""
|
||||||
|
if value.tzinfo is None:
|
||||||
|
value = value.replace(tzinfo=timezone.utc)
|
||||||
|
return value.astimezone().strftime("%d.%m.%Y, %H:%M")
|
||||||
|
|
||||||
|
|
||||||
|
templates.env.filters["datum"] = format_datum
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Hilfsfunktionen
|
# Hilfsfunktionen
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -6,6 +6,9 @@
|
|||||||
<div class="muted" style="font-size:.8rem; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;">
|
<div class="muted" style="font-size:.8rem; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;">
|
||||||
{{ link.url }}
|
{{ link.url }}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="muted" style="font-size:.75rem; margin-top:3px;">
|
||||||
|
🕓 hinzugefügt am {{ link.created_at | datum }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style="display:flex; gap:4px; flex-shrink:0;">
|
<div style="display:flex; gap:4px; flex-shrink:0;">
|
||||||
<button class="ghost" style="padding:4px 10px; font-size:.8rem;"
|
<button class="ghost" style="padding:4px 10px; font-size:.8rem;"
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
<div class="panel link-card" id="link-{{ link.id }}">
|
<div class="panel link-card" id="link-{{ link.id }}">
|
||||||
<form hx-put="/links/{{ link.id }}" hx-target="#link-{{ link.id }}" hx-swap="outerHTML"
|
<form hx-put="/links/{{ link.id }}" hx-target="#link-{{ link.id }}" hx-swap="outerHTML"
|
||||||
hx-disabled-elt="button">
|
hx-disabled-elt="button">
|
||||||
<div class="muted" style="font-size:.8rem; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; margin-bottom:8px;">
|
<div class="muted" style="font-size:.8rem; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;">
|
||||||
{{ link.url }}
|
{{ link.url }}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="muted" style="font-size:.75rem; margin:3px 0 10px;">
|
||||||
|
🕓 hinzugefügt am {{ link.created_at | datum }}
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Titel</label>
|
<label>Titel</label>
|
||||||
|
|||||||
Reference in New Issue
Block a user