feat: initialize events app with calendars, slots, tickets, and internal API
Some checks failed
Build and Deploy / build-and-deploy (push) Has been cancelled

Extract events/calendar functionality into standalone microservice:
- app.py and events_api.py from apps/events/
- Calendar blueprints (calendars, calendar, calendar_entries, calendar_entry, day, slots, slot, ticket_types, ticket_type)
- Templates for all calendar/event views including admin
- Dockerfile (APP_MODULE=app:app, IMAGE=events)
- entrypoint.sh (no Alembic - migrations managed by blog app)
- Gitea CI workflow for build and deploy

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
giles
2026-02-09 23:16:32 +00:00
commit 3c0fa45f8c
119 changed files with 7163 additions and 0 deletions

28
bp/day/admin/routes.py Normal file
View File

@@ -0,0 +1,28 @@
from __future__ import annotations
from quart import (
render_template, make_response, Blueprint
)
from suma_browser.app.authz import require_admin
def register():
bp = Blueprint("admin", __name__, url_prefix='/admin')
# ---------- Pages ----------
@bp.get("/")
@require_admin
async def admin(year: int, month: int, day: int, **kwargs):
from suma_browser.app.utils.htmx import is_htmx_request
# Determine which template to use based on request type
if not is_htmx_request():
# Normal browser request: full page with layout
html = await render_template("_types/day/admin/index.html")
else:
html = await render_template("_types/day/admin/_oob_elements.html")
return await make_response(html)
return bp

121
bp/day/routes.py Normal file
View File

@@ -0,0 +1,121 @@
from __future__ import annotations
from datetime import datetime, timezone, date, timedelta
from quart import (
request, render_template, make_response, Blueprint, g, abort, session as qsession
)
from suma_browser.app.bp.calendar.services import get_visible_entries_for_period
from suma_browser.app.bp.calendar_entries.routes import register as register_calendar_entries
from .admin.routes import register as register_admin
from suma_browser.app.redis_cacher import cache_page
from models.calendars import CalendarSlot # add this import
from sqlalchemy import select
from suma_browser.app.utils.htmx import is_htmx_request
def register():
bp = Blueprint("day", __name__, url_prefix='/day/<int:year>/<int:month>/<int:day>')
bp.register_blueprint(
register_calendar_entries()
)
bp.register_blueprint(
register_admin()
)
@bp.context_processor
async def inject_root():
view_args = getattr(request, "view_args", {}) or {}
day = view_args.get("day")
month = view_args.get("month")
year = view_args.get("year")
calendar = getattr(g, "calendar", None)
if not calendar:
return {}
try:
day_date = date(year, month, day)
except (ValueError, TypeError):
return {}
# Period: this day only
period_start = datetime(year, month, day, tzinfo=timezone.utc)
period_end = period_start + timedelta(days=1)
# Identity & admin flag
user = getattr(g, "user", None)
session_id = qsession.get("calendar_sid")
visible = await get_visible_entries_for_period(
sess=g.s,
calendar_id=calendar.id,
period_start=period_start,
period_end=period_end,
user=user,
session_id=session_id,
)
# --- NEW: slots for this weekday ---
weekday_attr = ["mon","tue","wed","thu","fri","sat","sun"][day_date.weekday()]
stmt = (
select(CalendarSlot)
.where(
CalendarSlot.calendar_id == calendar.id,
getattr(CalendarSlot, weekday_attr) == True, # noqa: E712
CalendarSlot.deleted_at.is_(None),
)
.order_by(CalendarSlot.time_start.asc(), CalendarSlot.id.asc())
)
result = await g.s.execute(stmt)
day_slots = list(result.scalars())
return {
"qsession": qsession,
"day_date": day_date,
"day": day,
"year": year,
"month": month,
"day_entries": visible.merged_entries,
"user_entries": visible.user_entries,
"confirmed_entries": visible.confirmed_entries,
"day_slots": day_slots, # <-- NEW
}
@bp.get("/")
@cache_page(tag="calendars")
async def show_day(year: int, month: int, day: int, **kwargs):
"""
Show a detail view for a single calendar day.
Visibility rules:
- Non-admin:
- all *confirmed* entries for that day (any user)
- all entries for current user/session (any state) for that day
(pending/ordered/provisional/confirmed)
- Admin:
- all confirmed + provisional + ordered entries for that day (all users)
- pending only for current user/session
"""
if not is_htmx_request():
# Normal browser request: full page with layout
html = await render_template(
"_types/day/index.html",
)
else:
html = await render_template(
"_types/day/_oob_elements.html",
)
return await make_response(html)
return bp