feat(ui): pretty_year_month helper, render month names in titles
pretty_year_month('2026-04') -> 'April 2026' for display. The
templates fall back to the raw year_month slug when the helper
returns nothing. Used by month.html and month_create.html to give
the nav a broadsheet feel; the URL routes still use the YYYY-MM
slug everywhere.
Refs #17
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
59ccb4db3c
commit
eb689cd9a1
2 changed files with 19 additions and 0 deletions
|
|
@ -83,6 +83,19 @@ def shift_year_month(year_month: str, delta: int) -> str:
|
|||
return f"{new_year:04d}-{new_month0 + 1:02d}"
|
||||
|
||||
|
||||
_MONTH_NAMES = [
|
||||
"", "January", "February", "March", "April", "May", "June",
|
||||
"July", "August", "September", "October", "November", "December",
|
||||
]
|
||||
|
||||
|
||||
def pretty_year_month(year_month: str) -> str:
|
||||
if not valid_year_month(year_month):
|
||||
return year_month
|
||||
year, month = year_month.split("-")
|
||||
return f"{_MONTH_NAMES[int(month)]} {year}"
|
||||
|
||||
|
||||
def get_month(db: Session, year_month: str) -> Month | None:
|
||||
stmt = select(Month).where(Month.year_month == year_month)
|
||||
return db.scalar(stmt)
|
||||
|
|
|
|||
|
|
@ -131,6 +131,9 @@ def view_month(
|
|||
"month_create.html",
|
||||
{
|
||||
"year_month": year_month,
|
||||
"pretty_year_month": month_service.pretty_year_month(year_month),
|
||||
"pretty_prev": month_service.pretty_year_month(prev_ym),
|
||||
"pretty_next": month_service.pretty_year_month(next_ym),
|
||||
"prev_year_month": prev_ym,
|
||||
"next_year_month": next_ym,
|
||||
"all_months": all_months,
|
||||
|
|
@ -148,6 +151,9 @@ def view_month(
|
|||
{
|
||||
"month": month,
|
||||
"year_month": year_month,
|
||||
"pretty_year_month": month_service.pretty_year_month(year_month),
|
||||
"pretty_prev": month_service.pretty_year_month(prev_ym),
|
||||
"pretty_next": month_service.pretty_year_month(next_ym),
|
||||
"prev_year_month": prev_ym,
|
||||
"next_year_month": next_ym,
|
||||
"all_months": all_months,
|
||||
|
|
|
|||
Loading…
Reference in a new issue