Let resolve_product run fully for POST, just skip redirects
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m0s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m0s
Instead of skipping resolve_product entirely for POST (leaving g.item_data unset and breaking templates), run the full resolution but suppress canonical-slug redirects. This sets g.item_data for the context processor so d.slug and other template vars work. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -48,9 +48,7 @@ def register():
|
|||||||
if raw_slug is None:
|
if raw_slug is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
# POST endpoints (cart, like) only need the slug — skip redirects
|
is_post = req.method == "POST"
|
||||||
if req.method == "POST":
|
|
||||||
return
|
|
||||||
|
|
||||||
# 1. If slug is INT → load product by ID
|
# 1. If slug is INT → load product by ID
|
||||||
if raw_slug.isdigit():
|
if raw_slug.isdigit():
|
||||||
@@ -69,18 +67,22 @@ def register():
|
|||||||
g.item_data = {"d": d, "slug": product["slug"], "liked": False}
|
g.item_data = {"d": d, "slug": product["slug"], "liked": False}
|
||||||
return
|
return
|
||||||
|
|
||||||
# Not deleted → redirect to canonical slug
|
# Not deleted → redirect to canonical slug (GET only)
|
||||||
canon = canonical_html_slug(product["slug"])
|
if not is_post:
|
||||||
return redirect(
|
canon = canonical_html_slug(product["slug"])
|
||||||
host_url(url_for("market.browse.product.product_detail", slug=canon))
|
return redirect(
|
||||||
)
|
host_url(url_for("market.browse.product.product_detail", slug=canon))
|
||||||
|
)
|
||||||
|
|
||||||
|
g.item_data = {"d": product, "slug": product["slug"], "liked": False}
|
||||||
|
return
|
||||||
|
|
||||||
# 2. Normal slug-based behaviour
|
# 2. Normal slug-based behaviour
|
||||||
if is_product_blocked(raw_slug):
|
if is_product_blocked(raw_slug):
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
canon = canonical_html_slug(raw_slug)
|
canon = canonical_html_slug(raw_slug)
|
||||||
if canon != raw_slug:
|
if canon != raw_slug and not is_post:
|
||||||
return redirect(
|
return redirect(
|
||||||
host_url(url_for("market.browse.product.product_detail", slug=canon))
|
host_url(url_for("market.browse.product.product_detail", slug=canon))
|
||||||
)
|
)
|
||||||
@@ -91,7 +93,7 @@ def register():
|
|||||||
)
|
)
|
||||||
if not d:
|
if not d:
|
||||||
abort(404)
|
abort(404)
|
||||||
g.item_data = {"d": d, "slug": canon, "liked": d["is_liked"]}
|
g.item_data = {"d": d, "slug": canon, "liked": d.get("is_liked", False)}
|
||||||
|
|
||||||
@bp.context_processor
|
@bp.context_processor
|
||||||
def context():
|
def context():
|
||||||
@@ -265,7 +267,6 @@ def register():
|
|||||||
|
|
||||||
return await render_template(
|
return await render_template(
|
||||||
"_types/product/_added.html",
|
"_types/product/_added.html",
|
||||||
d={"slug": slug},
|
|
||||||
cart=g.cart,
|
cart=g.cart,
|
||||||
item=ci,
|
item=ci,
|
||||||
total=total,
|
total=total,
|
||||||
|
|||||||
Reference in New Issue
Block a user