fix: nest market blueprint under post slug /<slug>/<market_slug>/
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 43s

Market app now follows the events app pattern — URLs include
the post slug prefix (e.g. /market/suma-market/). Hydrate
loads both post and market, verifying market belongs to post.
Scraper default URLs updated accordingly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
giles
2026-02-10 20:15:45 +00:00
parent b831d01113
commit 6202b31e8e
6 changed files with 53 additions and 40 deletions

83
app.py
View File

@@ -54,38 +54,68 @@ def create_app() -> "Quart":
app.jinja_loader,
])
# Market blueprint scoped under /<market_slug>/
# Market blueprint nested under post slug: /<slug>/<market_slug>/
app.register_blueprint(
register_market_bp(
url_prefix="/",
title=config()["coop_title"],
),
url_prefix="/<market_slug>",
url_prefix="/<slug>/<market_slug>",
)
# --- Auto-inject market_slug into url_for() calls ---
# --- Auto-inject slug and market_slug into url_for() calls ---
@app.url_value_preprocessor
def pull_market_slug(endpoint, values):
if values and "market_slug" in values:
g.market_slug = values.pop("market_slug")
def pull_slugs(endpoint, values):
if values:
if "slug" in values:
g.post_slug = values.pop("slug")
if "market_slug" in values:
g.market_slug = values.pop("market_slug")
@app.url_defaults
def inject_market_slug(endpoint, values):
slug = g.get("market_slug")
if slug and "market_slug" not in values:
if app.url_map.is_endpoint_expecting(endpoint, "market_slug"):
values["market_slug"] = slug
def inject_slugs(endpoint, values):
for attr, param in [("post_slug", "slug"), ("market_slug", "market_slug")]:
val = g.get(attr)
if val and param not in values:
if app.url_map.is_endpoint_expecting(endpoint, param):
values[param] = val
# --- Load market data for market_slug ---
# --- Load post and market data ---
@app.before_request
async def hydrate_market():
slug = getattr(g, "market_slug", None)
if not slug:
post_slug = getattr(g, "post_slug", None)
market_slug = getattr(g, "market_slug", None)
if not post_slug or not market_slug:
return
# Load post by slug
post = (
await g.s.execute(
select(Post).where(Post.slug == post_slug)
)
).scalar_one_or_none()
if not post:
abort(404)
g.post_data = {
"post": {
"id": post.id,
"title": post.title,
"slug": post.slug,
"feature_image": post.feature_image,
"html": post.html,
"status": post.status,
"visibility": post.visibility,
"is_page": post.is_page,
},
}
# Load market scoped to post
market = (
await g.s.execute(
select(MarketPlace).where(
MarketPlace.slug == slug,
MarketPlace.slug == market_slug,
MarketPlace.post_id == post.id,
MarketPlace.deleted_at.is_(None),
)
)
@@ -94,33 +124,16 @@ def create_app() -> "Quart":
abort(404)
g.market = market
# Load associated Post for context
post = (
await g.s.execute(
select(Post).where(Post.id == market.post_id)
)
).scalar_one_or_none()
if post:
g.post_data = {
"post": {
"id": post.id,
"title": post.title,
"slug": post.slug,
"feature_image": post.feature_image,
"html": post.html,
"status": post.status,
"visibility": post.visibility,
"is_page": post.is_page,
},
}
# --- Root route: market listing ---
@app.get("/")
async def markets_listing():
from sqlalchemy.orm import selectinload
markets = (
await g.s.execute(
select(MarketPlace)
.where(MarketPlace.deleted_at.is_(None))
.options(selectinload(MarketPlace.post))
.order_by(MarketPlace.name)
)
).scalars().all()