mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 08:11:08 -05:00
Add advanced search and trending parks features; update frontend dependencies and enhance home page layout
This commit is contained in:
@@ -29,6 +29,9 @@ from django.urls import reverse
|
||||
from django.shortcuts import get_object_or_404, render
|
||||
from decimal import InvalidOperation
|
||||
from django.views.generic import DetailView, ListView, CreateView, UpdateView
|
||||
from django.db.models import Count, Avg, Q
|
||||
from django.utils import timezone
|
||||
from datetime import timedelta
|
||||
import requests
|
||||
from decimal import Decimal, ROUND_DOWN
|
||||
from typing import Any, Optional, cast, Literal, Dict
|
||||
@@ -224,6 +227,56 @@ def reverse_geocode(request: HttpRequest) -> JsonResponse:
|
||||
return JsonResponse({"error": "Geocoding failed"}, status=500)
|
||||
|
||||
|
||||
class TrendingParksView(ListView):
|
||||
"""View for displaying trending/popular parks"""
|
||||
model = Park
|
||||
template_name = "parks/trending_parks.html"
|
||||
context_object_name = "parks"
|
||||
paginate_by = 20
|
||||
|
||||
def get_queryset(self) -> QuerySet[Park]:
|
||||
"""Get trending parks based on ride count, ratings, and recent activity"""
|
||||
# For now, order by a combination of factors that indicate popularity:
|
||||
# 1. Parks with more rides
|
||||
# 2. Higher average ratings
|
||||
# 3. More recent activity (reviews, photos, etc.)
|
||||
thirty_days_ago = timezone.now() - timedelta(days=30)
|
||||
|
||||
return (
|
||||
get_base_park_queryset()
|
||||
.annotate(
|
||||
recent_reviews=Count(
|
||||
'reviews',
|
||||
filter=Q(reviews__created_at__gte=thirty_days_ago)
|
||||
),
|
||||
recent_photos=Count(
|
||||
'photos',
|
||||
filter=Q(photos__created_at__gte=thirty_days_ago)
|
||||
)
|
||||
)
|
||||
.order_by(
|
||||
'-recent_reviews',
|
||||
'-recent_photos',
|
||||
'-ride_count',
|
||||
'-average_rating'
|
||||
)
|
||||
)
|
||||
|
||||
def get_template_names(self) -> list[str]:
|
||||
"""Return appropriate template for HTMX requests"""
|
||||
if self.request.htmx:
|
||||
return ["parks/partials/trending_parks.html"]
|
||||
return [self.template_name]
|
||||
|
||||
def get_context_data(self, **kwargs: Any) -> dict[str, Any]:
|
||||
context = super().get_context_data(**kwargs)
|
||||
context.update({
|
||||
'page_title': 'Trending Parks',
|
||||
'page_description': 'Discover the most popular theme parks with recent activity and high ratings.'
|
||||
})
|
||||
return context
|
||||
|
||||
|
||||
class ParkListView(HTMXFilterableMixin, ListView):
|
||||
model = Park
|
||||
template_name = "parks/enhanced_park_list.html"
|
||||
|
||||
Reference in New Issue
Block a user