mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 08:11:08 -05:00
yay
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
from django.views.generic import DetailView, ListView
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.core.serializers.json import DjangoJSONEncoder
|
||||
from django.urls import reverse
|
||||
from .models import Park, ParkArea
|
||||
from rides.models import Ride
|
||||
from core.views import SlugRedirectMixin
|
||||
@@ -64,28 +66,43 @@ 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')
|
||||
queryset = Park.objects.select_related('owner').prefetch_related('photos', 'rides')
|
||||
|
||||
# Filter by location if specified
|
||||
location = self.request.GET.get('location')
|
||||
# Apply filters
|
||||
search = self.request.GET.get('search', '').strip()
|
||||
location = self.request.GET.get('location', '').strip()
|
||||
status = self.request.GET.get('status', '').strip()
|
||||
|
||||
if search:
|
||||
queryset = queryset.filter(name__icontains=search) | queryset.filter(location__icontains=search)
|
||||
if location:
|
||||
queryset = queryset.filter(location__icontains=location)
|
||||
|
||||
# Filter by status if specified
|
||||
status = self.request.GET.get('status')
|
||||
queryset = queryset.filter(location=location)
|
||||
if status:
|
||||
queryset = queryset.filter(status=status)
|
||||
|
||||
return queryset.order_by('name')
|
||||
return queryset
|
||||
|
||||
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', '')
|
||||
|
||||
# Get unique locations for filter dropdown
|
||||
context['locations'] = list(Park.objects.values_list('location', flat=True)
|
||||
.distinct().order_by('location'))
|
||||
|
||||
# Add current filter values to context
|
||||
context['current_filters'] = {
|
||||
'search': self.request.GET.get('search', ''),
|
||||
'location': self.request.GET.get('location', ''),
|
||||
'status': self.request.GET.get('status', '')
|
||||
}
|
||||
|
||||
return context
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
# Check if this is an HTMX request
|
||||
if request.htmx:
|
||||
# If it is, return just the parks list partial
|
||||
self.template_name = 'parks/partials/park_list.html'
|
||||
return super().get(request, *args, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user