first commit

This commit is contained in:
pacnpal
2024-10-28 17:09:57 -04:00
commit 2e1b4d7af7
9993 changed files with 1182741 additions and 0 deletions

91
parks/views.py Normal file
View File

@@ -0,0 +1,91 @@
from django.views.generic import DetailView, ListView
from django.shortcuts import get_object_or_404
from .models import Park, ParkArea
from rides.models import Ride
from core.views import SlugRedirectMixin
class ParkDetailView(SlugRedirectMixin, DetailView):
model = Park
template_name = 'parks/park_detail.html'
context_object_name = 'park'
def get_object(self, queryset=None):
if queryset is None:
queryset = self.get_queryset()
slug = self.kwargs.get(self.slug_url_kwarg)
# Try to get by current or historical slug
return self.model.get_by_slug(slug)[0]
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['rides'] = Ride.objects.filter(
park=self.object
).select_related('coaster_stats')
context['areas'] = ParkArea.objects.filter(park=self.object)
return context
def get_redirect_url_pattern(self):
return 'park_detail'
class ParkAreaDetailView(SlugRedirectMixin, DetailView):
model = ParkArea
template_name = 'parks/area_detail.html'
context_object_name = 'area'
slug_url_kwarg = 'area_slug'
def get_object(self, queryset=None):
if queryset is None:
queryset = self.get_queryset()
park_slug = self.kwargs.get('park_slug')
area_slug = self.kwargs.get('area_slug')
# Try to get by current or historical slug
obj, is_old_slug = self.model.get_by_slug(area_slug)
if obj.park.slug != park_slug:
raise self.model.DoesNotExist("Park slug doesn't match")
return obj
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['rides'] = Ride.objects.filter(
area=self.object
).select_related('coaster_stats')
return context
def get_redirect_url_pattern(self):
return 'area_detail'
def get_redirect_url_kwargs(self):
return {
'park_slug': self.object.park.slug,
'area_slug': self.object.slug
}
class ParkListView(ListView):
model = Park
template_name = 'parks/park_list.html'
context_object_name = 'parks'
paginate_by = 12
def get_queryset(self):
queryset = Park.objects.select_related('owner')
# Filter by location if specified
location = self.request.GET.get('location')
if location:
queryset = queryset.filter(location__icontains=location)
# Filter by status if specified
status = self.request.GET.get('status')
if status:
queryset = queryset.filter(status=status)
return queryset.order_by('name')
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
# Add list of locations for the filter dropdown
context['locations'] = Park.objects.values_list(
'location', flat=True
).distinct().order_by('location')
context['selected_location'] = self.request.GET.get('location', '')
return context