feat: decouple blog from shared_lib, add app-owned models
Phase 1-3 of decoupling: - path_setup.py adds project root to sys.path - Blog-owned models in blog/models/ (ghost_content, snippet, tag_group) - Re-export shims for shared models (user, kv, magic_link, menu_item) - All imports updated: shared.infrastructure, shared.db, shared.browser, etc. - No more cross-app post_id FKs in calendar/market/page_config Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -12,9 +12,9 @@ from quart import (
|
||||
)
|
||||
from sqlalchemy import select, delete
|
||||
|
||||
from suma_browser.app.authz import require_admin
|
||||
from suma_browser.app.utils.htmx import is_htmx_request
|
||||
from suma_browser.app.redis_cacher import invalidate_tag_cache
|
||||
from shared.browser.app.authz import require_admin
|
||||
from shared.browser.app.utils.htmx import is_htmx_request
|
||||
from shared.browser.app.redis_cacher import invalidate_tag_cache
|
||||
|
||||
from models.tag_group import TagGroup, TagGroupTag
|
||||
from models.ghost_content import Tag
|
||||
|
||||
@@ -2,10 +2,10 @@ from quart import request
|
||||
|
||||
from typing import Iterable, Optional, Union
|
||||
|
||||
from suma_browser.app.filters.qs_base import (
|
||||
from shared.browser.app.filters.qs_base import (
|
||||
KEEP, _norm, make_filter_set, build_qs,
|
||||
)
|
||||
from suma_browser.app.filters.query_types import BlogQuery
|
||||
from shared.browser.app.filters.query_types import BlogQuery
|
||||
|
||||
|
||||
def decode() -> BlogQuery:
|
||||
|
||||
@@ -13,7 +13,7 @@ import httpx
|
||||
from quart import Blueprint, request, jsonify, g
|
||||
from sqlalchemy import select, or_
|
||||
|
||||
from suma_browser.app.authz import require_admin, require_login
|
||||
from shared.browser.app.authz import require_admin, require_login
|
||||
from models import Snippet
|
||||
from .ghost_admin_token import make_ghost_admin_jwt
|
||||
|
||||
|
||||
@@ -13,11 +13,11 @@ from sqlalchemy.orm.attributes import flag_modified # for non-Mutable JSON colu
|
||||
from models.ghost_content import (
|
||||
Post, Author, Tag, PostAuthor, PostTag
|
||||
)
|
||||
from models.page_config import PageConfig
|
||||
from cart.models.page_config import PageConfig
|
||||
|
||||
# User-centric membership models
|
||||
from models import User
|
||||
from models.ghost_membership_entities import (
|
||||
from shared.models import User
|
||||
from shared.models.ghost_membership_entities import (
|
||||
GhostLabel, UserLabel,
|
||||
GhostNewsletter, UserNewsletter,
|
||||
GhostTier, GhostSubscription,
|
||||
@@ -29,7 +29,7 @@ from urllib.parse import quote
|
||||
|
||||
GHOST_ADMIN_API_URL = os.environ["GHOST_ADMIN_API_URL"]
|
||||
|
||||
from suma_browser.app.utils import (
|
||||
from shared.browser.app.utils import (
|
||||
utcnow
|
||||
)
|
||||
|
||||
@@ -242,10 +242,10 @@ async def _upsert_post(sess: AsyncSession, gp: Dict[str, Any], author_map: Dict[
|
||||
# Auto-create PageConfig for pages
|
||||
if obj.is_page:
|
||||
existing_pc = (await sess.execute(
|
||||
select(PageConfig).where(PageConfig.post_id == obj.id)
|
||||
select(PageConfig).where(PageConfig.container_type == "page", PageConfig.container_id == obj.id)
|
||||
)).scalar_one_or_none()
|
||||
if existing_pc is None:
|
||||
sess.add(PageConfig(post_id=obj.id, features={}))
|
||||
sess.add(PageConfig(container_type="page", container_id=obj.id, features={}))
|
||||
await sess.flush()
|
||||
|
||||
return obj
|
||||
|
||||
@@ -6,7 +6,7 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.orm import selectinload, joinedload
|
||||
|
||||
from models.ghost_content import Post, Author, Tag, PostTag
|
||||
from models.page_config import PageConfig
|
||||
from cart.models.page_config import PageConfig
|
||||
from models.tag_group import TagGroup, TagGroupTag
|
||||
|
||||
|
||||
|
||||
@@ -15,15 +15,15 @@ from quart import (
|
||||
url_for,
|
||||
)
|
||||
from .ghost_db import DBClient # adjust import path
|
||||
from db.session import get_session
|
||||
from shared.db.session import get_session
|
||||
from .filters.qs import makeqs_factory, decode
|
||||
from .services.posts_data import posts_data
|
||||
from .services.pages_data import pages_data
|
||||
|
||||
from suma_browser.app.redis_cacher import cache_page, invalidate_tag_cache
|
||||
from suma_browser.app.utils.htmx import is_htmx_request
|
||||
from suma_browser.app.authz import require_admin
|
||||
from utils import host_url
|
||||
from shared.browser.app.redis_cacher import cache_page, invalidate_tag_cache
|
||||
from shared.browser.app.utils.htmx import is_htmx_request
|
||||
from shared.browser.app.authz import require_admin
|
||||
from shared.utils import host_url
|
||||
|
||||
def register(url_prefix, title):
|
||||
blogs_bp = Blueprint("blog", __name__, url_prefix)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from ..ghost_db import DBClient # adjust import path
|
||||
from sqlalchemy import select
|
||||
from models.ghost_content import PostLike
|
||||
from models.calendars import CalendarEntry, CalendarEntryPost
|
||||
from events.models.calendars import CalendarEntry, CalendarEntryPost
|
||||
from quart import g
|
||||
|
||||
async def posts_data(
|
||||
@@ -89,11 +89,12 @@ async def posts_data(
|
||||
# Get all confirmed entries associated with these posts
|
||||
from sqlalchemy.orm import selectinload
|
||||
entries_result = await session.execute(
|
||||
select(CalendarEntry, CalendarEntryPost.post_id)
|
||||
select(CalendarEntry, CalendarEntryPost.content_id)
|
||||
.join(CalendarEntryPost, CalendarEntry.id == CalendarEntryPost.entry_id)
|
||||
.options(selectinload(CalendarEntry.calendar)) # Eagerly load calendar
|
||||
.where(
|
||||
CalendarEntryPost.post_id.in_(post_ids),
|
||||
CalendarEntryPost.content_type == "post",
|
||||
CalendarEntryPost.content_id.in_(post_ids),
|
||||
CalendarEntryPost.deleted_at.is_(None),
|
||||
CalendarEntry.deleted_at.is_(None),
|
||||
CalendarEntry.state == "confirmed"
|
||||
|
||||
@@ -10,8 +10,8 @@ from ..ghost.ghost_sync import (
|
||||
sync_single_author,
|
||||
sync_single_tag,
|
||||
)
|
||||
from suma_browser.app.redis_cacher import clear_cache
|
||||
from suma_browser.app.csrf import csrf_exempt
|
||||
from shared.browser.app.redis_cacher import clear_cache
|
||||
from shared.browser.app.csrf import csrf_exempt
|
||||
|
||||
ghost_webhooks = Blueprint("ghost_webhooks", __name__, url_prefix="/__ghost-webhook")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user