mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 06:11:07 -05:00
feat: Implement ride management views and utility functions
- Added functions for checking user privileges, handling photo uploads, preparing form data, and managing form errors. - Created views for listing, creating, updating, and displaying rides, including category-specific views. - Integrated submission handling for ride changes and improved user feedback through messages. - Enhanced data handling with appropriate context and queryset management for better performance and usability.
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -1,12 +1,12 @@
|
||||
# Django settings for thrillwiki project.
|
||||
"""
|
||||
Django settings for thrillwiki project.
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
import os
|
||||
|
||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = "django-insecure-=0)^0#h#k$0@$8$ys=^$0#h#k$0@$8$ys=^"
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
@@ -46,6 +46,7 @@ INSTALLED_APPS = [
|
||||
"moderation",
|
||||
"history_tracking",
|
||||
"designers",
|
||||
"analytics",
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
@@ -62,6 +63,7 @@ MIDDLEWARE = [
|
||||
"django.middleware.cache.FetchFromCacheMiddleware",
|
||||
"simple_history.middleware.HistoryRequestMiddleware",
|
||||
"django_htmx.middleware.HtmxMiddleware",
|
||||
"analytics.middleware.PageViewMiddleware", # Add our page view tracking
|
||||
]
|
||||
|
||||
ROOT_URLCONF = "thrillwiki.urls"
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
from django.shortcuts import render
|
||||
from django.views.generic import TemplateView
|
||||
from django.db.models import Count, Q
|
||||
from django.db.models import Count, Q, Value, CharField
|
||||
from django.db.models.functions import Concat
|
||||
from django.core.cache import cache
|
||||
from parks.models import Park
|
||||
from rides.models import Ride
|
||||
from companies.models import Company, Manufacturer
|
||||
from analytics.models import PageView
|
||||
from django.conf import settings
|
||||
import random
|
||||
import os
|
||||
|
||||
|
||||
@@ -27,15 +31,60 @@ class HomeView(TemplateView):
|
||||
'total_roller_coasters': Ride.objects.filter(category='RC').count(),
|
||||
}
|
||||
|
||||
# Get popular parks (based on average rating)
|
||||
context['popular_parks'] = Park.objects.exclude(
|
||||
# Try to get trending items from cache first
|
||||
trending_parks = cache.get('trending_parks')
|
||||
trending_rides = cache.get('trending_rides')
|
||||
|
||||
# If not in cache, get them directly and cache them
|
||||
if trending_parks is None:
|
||||
try:
|
||||
trending_parks = list(PageView.get_trending_items(Park, hours=24, limit=10))
|
||||
if trending_parks:
|
||||
cache.set('trending_parks', trending_parks, 3600) # Cache for 1 hour
|
||||
else:
|
||||
# Fallback to highest rated parks if no trending data
|
||||
trending_parks = Park.objects.exclude(
|
||||
average_rating__isnull=True
|
||||
).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]
|
||||
|
||||
if trending_rides is None:
|
||||
try:
|
||||
trending_rides = list(PageView.get_trending_items(Ride, hours=24, limit=10))
|
||||
if trending_rides:
|
||||
cache.set('trending_rides', trending_rides, 3600) # Cache for 1 hour
|
||||
else:
|
||||
# Fallback to highest rated rides if no trending data
|
||||
trending_rides = Ride.objects.exclude(
|
||||
average_rating__isnull=True
|
||||
).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]
|
||||
|
||||
# Get highest rated items (mix of parks and rides)
|
||||
highest_rated_parks = list(Park.objects.exclude(
|
||||
average_rating__isnull=True
|
||||
).order_by('-average_rating')[:5]
|
||||
).order_by('-average_rating')[:20]) # Get more items to randomly select from
|
||||
|
||||
# Get popular rides (based on average rating)
|
||||
context['popular_rides'] = Ride.objects.exclude(
|
||||
highest_rated_rides = list(Ride.objects.exclude(
|
||||
average_rating__isnull=True
|
||||
).order_by('-average_rating')[:5]
|
||||
).order_by('-average_rating')[:20]) # Get more items to randomly select from
|
||||
|
||||
# Combine and shuffle highest rated items
|
||||
all_highest_rated = highest_rated_parks + highest_rated_rides
|
||||
random.shuffle(all_highest_rated)
|
||||
|
||||
# Keep the same context variable names for template compatibility
|
||||
context['popular_parks'] = trending_parks
|
||||
context['popular_rides'] = trending_rides
|
||||
context['highest_rated'] = all_highest_rated[:10] # Take first 10 after shuffling
|
||||
|
||||
return context
|
||||
|
||||
@@ -76,6 +125,7 @@ class SearchView(TemplateView):
|
||||
).prefetch_related('rides')[:10]
|
||||
|
||||
return context
|
||||
|
||||
def environment_and_settings_view(request):
|
||||
# Get all environment variables
|
||||
env_vars = dict(os***REMOVED***iron)
|
||||
@@ -86,4 +136,4 @@ def environment_and_settings_view(request):
|
||||
return render(request, 'environment_and_settings.html', {
|
||||
'env_vars': env_vars,
|
||||
'settings_vars': settings_vars
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user