Add market_product_url helper for correct product URLs
market_url('/product/...') was missing the /<page_slug>/<market_slug>/
prefix required by the market app's route structure. New helper
market_product_url() resolves the prefix from request context
(g.post_slug/g.market_slug in market app, g.page_slug + market_place
in cart app).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -13,7 +13,7 @@ from shared.browser.app.csrf import generate_csrf_token
|
||||
from shared.browser.app.authz import has_access
|
||||
from shared.browser.app.filters import register as register_filters
|
||||
|
||||
from .urls import coop_url, market_url, cart_url, events_url, login_url, page_cart_url
|
||||
from .urls import coop_url, market_url, cart_url, events_url, login_url, page_cart_url, market_product_url
|
||||
|
||||
|
||||
def setup_jinja(app: Quart) -> None:
|
||||
@@ -94,6 +94,7 @@ def setup_jinja(app: Quart) -> None:
|
||||
app.jinja_env.globals["events_url"] = events_url
|
||||
app.jinja_env.globals["login_url"] = login_url
|
||||
app.jinja_env.globals["page_cart_url"] = page_cart_url
|
||||
app.jinja_env.globals["market_product_url"] = market_product_url
|
||||
|
||||
# register jinja filters
|
||||
register_filters(app)
|
||||
|
||||
@@ -43,6 +43,24 @@ def page_cart_url(page_slug: str, path: str = "/") -> str:
|
||||
return cart_url(f"/{page_slug}{path}")
|
||||
|
||||
|
||||
def market_product_url(product_slug: str, suffix: str = "", market_place=None) -> str:
|
||||
"""Build a market product URL with the correct page/market prefix.
|
||||
|
||||
Resolves the prefix from:
|
||||
- market app context: g.post_slug + g.market_slug
|
||||
- cart app context: g.page_slug + market_place.slug
|
||||
"""
|
||||
from quart import g
|
||||
|
||||
page_slug = getattr(g, "post_slug", None) or getattr(g, "page_slug", None)
|
||||
ms = getattr(g, "market_slug", None) or (
|
||||
getattr(market_place, "slug", None) if market_place else None
|
||||
)
|
||||
prefix = f"/{page_slug}/{ms}" if page_slug and ms else ""
|
||||
tail = f"/{suffix}" if suffix else "/"
|
||||
return market_url(f"{prefix}/product/{product_slug}{tail}")
|
||||
|
||||
|
||||
def login_url(next_url: str = "") -> str:
|
||||
if next_url:
|
||||
return coop_url(f"/auth/login/?next={quote(next_url, safe='')}")
|
||||
|
||||
Reference in New Issue
Block a user