feat: decouple events from shared_lib, add app-owned models

Phase 1-3 of decoupling:
- path_setup.py adds project root to sys.path
- Events-owned models in events/models/ (calendars with all related models)
- All imports updated: shared.infrastructure, shared.db, shared.browser, etc.
- Calendar uses container_type/container_id instead of post_id FK
- CalendarEntryPost uses content_type/content_id (generic content refs)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
giles
2026-02-11 12:46:36 +00:00
parent 95d954fdb6
commit 154f968296
37 changed files with 506 additions and 93 deletions

View File

@@ -7,16 +7,17 @@ from sqlalchemy import select
from models.calendars import Calendar
from .services.calendars import (
create_calendar as svc_create_calendar,
)
from ..calendar.routes import register as register_calendar
from suma_browser.app.redis_cacher import cache_page, clear_cache
from shared.browser.app.redis_cacher import cache_page, clear_cache
from suma_browser.app.authz import require_admin
from suma_browser.app.utils.htmx import is_htmx_request
from shared.browser.app.authz import require_admin
from shared.browser.app.utils.htmx import is_htmx_request
def register():
@@ -78,7 +79,7 @@ def register():
cals = (
await g.s.execute(
select(Calendar)
.where(Calendar.post_id == post_id, Calendar.deleted_at.is_(None))
.where(Calendar.container_type == "page", Calendar.container_id == post_id, Calendar.deleted_at.is_(None))
.order_by(Calendar.name.asc())
)
).scalars().all()

View File

@@ -4,7 +4,7 @@ from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from models.calendars import Calendar
from models.ghost_content import Post # for FK existence checks
from blog.models.ghost_content import Post # for FK existence checks
import unicodedata
import re
@@ -12,7 +12,7 @@ import re
class CalendarError(ValueError):
"""Base error for calendar service operations."""
from suma_browser.app.utils import (
from shared.browser.app.utils import (
utcnow
)
@@ -51,7 +51,8 @@ async def soft_delete(sess: AsyncSession, post_slug: str, calendar_slug: str) ->
cal = (
await sess.execute(
select(Calendar)
.join(Post, Calendar.post_id == Post.id)
.join(Post, Calendar.container_id == Post.id)
.where(Calendar.container_type == "page")
.where(
Post.slug == post_slug,
Calendar.slug == calendar_slug,
@@ -89,7 +90,7 @@ async def create_calendar(sess: AsyncSession, post_id: int, name: str) -> Calend
# Look for existing (including soft-deleted)
q = await sess.execute(
select(Calendar).where(Calendar.post_id == post_id, Calendar.name == name)
select(Calendar).where(Calendar.container_type == "page", Calendar.container_id == post_id, Calendar.name == name)
)
existing = q.scalar_one_or_none()
@@ -100,7 +101,7 @@ async def create_calendar(sess: AsyncSession, post_id: int, name: str) -> Calend
return existing
raise CalendarError(f'Calendar with slug "{slug}" already exists for post {post_id}.')
cal = Calendar(post_id=post_id, name=name, slug=slug)
cal = Calendar(container_type="page", container_id=post_id, name=name, slug=slug)
sess.add(cal)
await sess.flush()
return cal