Make /random redirect to any public product or content page

Removed media-only filter and popout_player_enabled gate. Now picks
from all public items and redirects to the correct /p/ or /c/ URL.
This commit is contained in:
russell@unturf.com 2026-02-09 12:54:03 -05:00
parent a3725e8070
commit df1cd64851

View file

@ -234,42 +234,19 @@ def player_json(request):
@view_config(route_name="random")
def random_media(request):
"""Redirect to a random public media item."""
# Check if feature is enabled
if not request.popout_player_enabled:
return HTTPNotFound()
# Get current shop
def random_product(request):
"""Redirect to a random public product or content page."""
shop = request.shop
if not shop:
return HTTPNotFound()
# Query all public products from the shop
shop_products = get_products_from_a_shop(shop, visibility=1)
products = list(get_products_from_a_shop(shop, visibility=1))
if not products:
return HTTPNotFound("No public items available")
# Filter to only media items
media_products = []
for p in shop_products:
# Check for preview or product file with media type
if "preview" in p.extensions:
ext = p.extensions.get("preview")
if get_media_type(ext):
media_products.append(p)
elif "product" in p.extensions:
ext = p.extensions.get("product")
if get_media_type(ext):
media_products.append(p)
if not media_products:
return HTTPNotFound("No media available")
# Pick a random product
random_product = random.choice(media_products)
# Redirect to player
return HTTPFound(location=f"/player/{random_product.id}")
chosen = random.choice(products)
p_or_c = "p" if chosen.is_sellable else "c"
return HTTPFound(location=f"/{p_or_c}/{chosen.id}/{chosen.slug}")
@view_config(route_name="tv", renderer="tv.j2")