mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 05:11:09 -05:00
Ensure park and ride slugs are valid before displaying links
Prevents 500 errors by filtering out parks and rides with null or empty slugs from trending lists and excludes them from database queries where slugs are required. Additionally, it adds conditional rendering in templates to handle parks without slugs gracefully. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 0bdea3fb-49ea-4863-b501-fa6f5af0cbf0 Replit-Commit-Checkpoint-Type: intermediate_checkpoint
This commit is contained in:
@@ -41,6 +41,8 @@ class HomeView(TemplateView):
|
||||
trending_parks = list(
|
||||
PageView.get_trending_items(Park, hours=24, limit=10)
|
||||
)
|
||||
# Filter out any parks with invalid slugs
|
||||
trending_parks = [p for p in trending_parks if getattr(p, 'slug', None)]
|
||||
if trending_parks:
|
||||
cache.set(
|
||||
"trending_parks", trending_parks, 3600
|
||||
@@ -49,18 +51,20 @@ class HomeView(TemplateView):
|
||||
# Fallback to highest rated parks if no trending data
|
||||
trending_parks = Park.objects.exclude(
|
||||
average_rating__isnull=True
|
||||
).order_by("-average_rating")[:10]
|
||||
).exclude(slug__isnull=True).exclude(slug__exact='').order_by("-average_rating")[:10]
|
||||
except Exception:
|
||||
# Fallback to highest rated parks if trending calculation fails
|
||||
trending_parks = Park.objects.exclude(
|
||||
average_rating__isnull=True
|
||||
).order_by("-average_rating")[:10]
|
||||
).exclude(slug__isnull=True).exclude(slug__exact='').order_by("-average_rating")[:10]
|
||||
|
||||
if trending_rides is None:
|
||||
try:
|
||||
trending_rides = list(
|
||||
PageView.get_trending_items(Ride, hours=24, limit=10)
|
||||
)
|
||||
# Filter out any rides with invalid slugs
|
||||
trending_rides = [r for r in trending_rides if getattr(r, 'slug', None)]
|
||||
if trending_rides:
|
||||
cache.set(
|
||||
"trending_rides", trending_rides, 3600
|
||||
@@ -69,24 +73,24 @@ class HomeView(TemplateView):
|
||||
# Fallback to highest rated rides if no trending data
|
||||
trending_rides = Ride.objects.exclude(
|
||||
average_rating__isnull=True
|
||||
).order_by("-average_rating")[:10]
|
||||
).exclude(slug__isnull=True).exclude(slug__exact='').order_by("-average_rating")[:10]
|
||||
except Exception:
|
||||
# Fallback to highest rated rides if trending calculation fails
|
||||
trending_rides = Ride.objects.exclude(
|
||||
average_rating__isnull=True
|
||||
).order_by("-average_rating")[:10]
|
||||
).exclude(slug__isnull=True).exclude(slug__exact='').order_by("-average_rating")[:10]
|
||||
|
||||
# Get highest rated items (mix of parks and rides)
|
||||
highest_rated_parks = list(
|
||||
Park.objects.exclude(average_rating__isnull=True).order_by(
|
||||
"-average_rating"
|
||||
)[:20]
|
||||
Park.objects.exclude(average_rating__isnull=True)
|
||||
.exclude(slug__isnull=True).exclude(slug__exact='')
|
||||
.order_by("-average_rating")[:20]
|
||||
) # Get more items to randomly select from
|
||||
|
||||
highest_rated_rides = list(
|
||||
Ride.objects.exclude(average_rating__isnull=True).order_by(
|
||||
"-average_rating"
|
||||
)[:20]
|
||||
Ride.objects.exclude(average_rating__isnull=True)
|
||||
.exclude(slug__isnull=True).exclude(slug__exact='')
|
||||
.order_by("-average_rating")[:20]
|
||||
) # Get more items to randomly select from
|
||||
|
||||
# Combine and shuffle highest rated items
|
||||
|
||||
Reference in New Issue
Block a user